Hi, the first query seemes to be incorrect. If you want to display only 5 product you need to limit your query adding at the end the instraction LIMIT 0,5 ( where 5 is the product number you want dislay ). Howhever, the better way is to create only one query using LEFT JOIN. Sonthing like:
PHP Code:
$result=mysql_query("SELECT product.name AS name, order.products_product_id AS product_id, COUNT(order.*) AS mostPopular FROM products AS product LEFT JOIN order_details ON product.products_product_id = order.products_product_id GROUP BY order.products_product_id ORDER BY mostPopular DESC LIMIT 0,5");
Check php manual, mysql_fecth_array returns a mysql table. If you want to display all rows about your query you need to use that instruction in a while as:
PHP Code:
while( $row = mysql_fetch_array( $result ) )
{
echo '<a href="details/'.$row['product_id'].'"><li>'.$row['name'].'</li></a>';
}
But attenction, you use product_product_id in the query, and product_id in the while.
Bookmarks