MGHosted.net
12-31-2004, 04:29 PM
Hi Guys,
I've tried to do something, and I know it wont work, but I can't seem to get my head around what I'm trying to do and write code for it.
This is my code
$exploded = explode(",", $currentfavourites);
foreach($exploded as $key=>$cid) {
if($cid == $id) {
echo "<br />Already in favourites";
} else {
echo "<br />Added to favourites!";
}
}
In some code above that, It queries a database, and then gets 1 row only, it then assigns one of the colums to $currentfavourites.
It's in this format: number,number,number (e.g. 1,2,3)
The one I'm using to test is 1,2
I'm on a page which is page.php?id= which also gets another query to get another row, which is different. The id for that row is $id.
So what my code does, is explode the 1,2 in 1 and 2, so I think loop it using the foreach, and then I say, if the ID is the same as the other ID, echo Already in favourites. So it'll go 1 = 1, and return already, then it'll go 1 = 2 and echo added when I dont want it to say that, I only want it for check the current ID.
If any of that makes sense, do you know a way to fix it?
I've tried to do something, and I know it wont work, but I can't seem to get my head around what I'm trying to do and write code for it.
This is my code
$exploded = explode(",", $currentfavourites);
foreach($exploded as $key=>$cid) {
if($cid == $id) {
echo "<br />Already in favourites";
} else {
echo "<br />Added to favourites!";
}
}
In some code above that, It queries a database, and then gets 1 row only, it then assigns one of the colums to $currentfavourites.
It's in this format: number,number,number (e.g. 1,2,3)
The one I'm using to test is 1,2
I'm on a page which is page.php?id= which also gets another query to get another row, which is different. The id for that row is $id.
So what my code does, is explode the 1,2 in 1 and 2, so I think loop it using the foreach, and then I say, if the ID is the same as the other ID, echo Already in favourites. So it'll go 1 = 1, and return already, then it'll go 1 = 2 and echo added when I dont want it to say that, I only want it for check the current ID.
If any of that makes sense, do you know a way to fix it?
