Reply to thread

I have a session with some stored id's which relate to rows in a mySQL table.


This is fine - i can use a for each loop and they all appear. However, in this session an id may appear twice which is perfectly ok.


The problem arises when i go to get information relating to the ids.


Here is what i have so far:


$query = "SELECT * FROM products WHERE id IN(";

foreach($_SESSION['cart'] as $key => $value){

$query .= $value.", ";

}

$query = substr($query,0,-2).")";

echo $query;

$result = mysql_query($query);


if(!$result) {

die("<p>There was an error with your basket</p>".mysql_error());

}


while($rows = mysql_fetch_array($result)){

echo "<p>".$rows['name']."</p>";

}


This is all works ok but has one problem, if i have an id in the session that appears twice - it will only echo $rows['name'] once. i dont know how i can work around this?


Is there a way i can get it to display the info twice OR a way to indicate the number of times that id appears (like a quantity?)


Any help would be appreciated :)

Sorry, i'm not familiar with the hash array?

ah sorry, i see what you mean by hash array - i know this as an associative array.


still a bit unsure what you mean!


thank you for your continued help!


Loading…
Back
Top