我有一个“订单”表,它保存了网站上的所有订单。它以下列方式保存数据:
ID | Session_id | image | item | extra | customer_name
样品日期
12 | sdgfafjhsf | image1.jpg | coffee | milk | roger
13 | sdgfafjhsf | image1.jpg | muffin | jam | roger
14 | fjgjgsdfjg | image3.jpg | coffee | none | John
目前我有 PHP 访问数据库并一一吐出所有列表。
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("store") or die(mysql_error()) ;
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM orders WHERE status ='ordered'") or die(mysql_error()); //Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "$info[customer_name] <img src='cameras/$info[image]'/> : $info[item] with $info[extras] <br />";
}
理想情况下,我希望数据按会话 ID 分组。因此,它会一次性打印出客户的姓名和图像,然后打印出与其相关联的所有项目。
例如。罗杰,咖啡,牛奶,松饼,果酱
有任何想法吗?谢谢!