我有两张桌子:
ROOMS
room_id>>>room_name
1 次足底按摩 2 脸部按摩 3 背部按摩
订购room_id
>>>start_date>>>>>>>end_date>>>>>>>>价格
1 2012.09.10 2012.09.11 100 1 2012.09.11 2012.09.13 200 2 2012.11.11 2012.11.13 100 3 2012.12.11 2012.12.13 500
我想输出这样的结果:
1号房间:
2012.09.10 2012.09.11 100 2012.09.11 2012.09.13 200
2号房间:
2012.11.11 2012.11.13 100
3号房间:
2012.12.11 2012.12.13 500
代码:
$query_spa = "SELECT
rooms.room_id,
rooms.room_name,
orders.start_date,
orders.end_date,
orders.price
FROM rooms
INNER JOIN orders
ON
rooms.room_id =orders.room_id";
$spa = mysql_query($query_spa, $localhost) or die(mysql_error());
$results = array();
while($line = mysql_fetch_array($spa, MYSQL_ASSOC)){
$results[] = $line;
}
$groups = array();
foreach($results as $item)
$groups[$item['room_id']][] = $item;
foreach($groups as $value => $items)
echo 'room number ' . $value . ' : ' ;
for ($i=0; $i< count($items);$i++)
{
echo $items[$i]['start_date'] ;
echo $items[$i]['end_date'] ;
echo $items[$i]['price'] ;
}
输出:
1号房:2号房:3号房:2012.12.11 2012.12.13 500