Hi there,
I’m struggling with some MYSQL and PHP code… I want to display the 5 most popular products so i wrote this sql query:
[CODE]
SELECT products_product_id, COUNT(*) AS mostPopular FROM order_details GROUP BY products_product_id ORDER BY mostPopular DESC
That’s working great, now the second part. My product names are in a different table (products) so i want to display the 5 most popular products from the table products.
So this is where it goes wrong, the code below isn’t working and probably it’s something very stupid… but i can’t find it, aaah! ?
[CODE]
function getMostPopular(){
$result=mysql_query(“SELECT products_product_id, COUNT(*) AS mostPopular FROM order_details GROUP BY products_product_id ORDER BY mostPopular DESC”);
$row=mysql_fetch_array($result);
$max_count = $row[‘products_product_id’];
$sql=mysql_query(“SELECT * FROM products WHERE product_id=$max_count”);
while($rij = mysql_fetch_array($sql)){
echo ‘<a href=”details/’.$rij[‘product_id’].'”><li>’.$rij[‘name’].'</li></a>’;
}
}
Can anybody help me?