Thanks for reading!
I have a record shop online written in php and ezsql.
I am trying to display a list of records from my sql database as suggestions for the customer to add to his cart. These records must not already be in the cart at the time the suggestions are displayed!
The code below partially works. If there is one record in the cart by Madonna, it will show a list of other Madonna records as long as the id in the table isn’t the same which is correct. i.e. if “true blue” is in the cart already, the suggestions list should not contain “true blue” as the user already has added it to their cart.
The problem I’ve got is that if there is more than one record by Madonna in the cart, it displays one or more records in the suggestion list that are already in the cart which is incorrect. I cant seem to work out why. The code iterates through the basket so I should get unique suggestions. Any help appreciated - I’m almost there!
The table in the database contains id, artist, title, price.
The session variable “item” contains product_id, artist
<?php echo 'You may be interested in these records:
'; foreach ($_SESSION['item'] as $item ) { $iid=$item['product_id']; $basket = $db->get_results("SELECT * FROM records WHERE artist LIKE '".$item['artist']."' and id !=$iid "); if (is_array($basket) || is_object($basket)) { foreach ( $basket as $row ) { echo "matching ".$row->id." with ".$item['product_id']."
";
//if ($row->id !=$iid)
//{
$art= shorten("$row->artist", 25);
$tit= shorten("$row->title", 25);
echo $row->id."
";
echo "
".$art.'
';
echo "
".$tit.'
';
echo "£".$row->price;
}
}
}
?>