Jump to content

Arranging An Array


Rachel

Recommended Posts

Is there anyway to arrange an array like:

 

Monday 12.00 14.00 16.00

Tuesday 12.00 14.00 16.00 etc

 

instead of

Monday 12.00

Monday 14.00

Monday 16.00

Tuesday 12.00

Tuesday 14.00

Tuesday 16.00 etc

 

$sql4 = "select * from time_list where loc_id = $location_id and film_id = $film_id order by day asc";
		$result4=mysql_query($sql4);

while($rows4=mysql_fetch_array($result4)){
			$time_id = $rows4['time_id'];

<?php echo $rows4['day']; ?></td>

<td><a href ="seating.php?cine=<?php echo $location_id; ?>&film=<?php echo $film_id; ?>&time=<?php echo $time_id; ?>"><?php echo $rows4['time']; }?>

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/228503-arranging-an-array/
Share on other sites

You don't rearrange the array, you just need to check when to echo the day:

 

$day = '';
while($rows4 = mysql_fetch_array($result4)) {
   if($day != $rows4['day']) {
      echo $rows4['day'];
      $day = $rows4['day'];
   }
   echo $rows4['time_id'];
}

Link to comment
https://forums.phpfreaks.com/topic/228503-arranging-an-array/#findComment-1178204
Share on other sites

Big thanks, that woked how I wanted it to, but is there any way to order by time as the times are out of order?

 

eg.

friday 14.00 16.00 12.00

monday 14.00 12.00 16.00

saturday 16.00 14.00 12.00

sunday 14.00 16.00 12.00

thursday 14.00 12.00 16.00

tuesday 14.00 16.00 12.00

wednesday 12.00 16.00 14.00

 

Thankyou.

Link to comment
https://forums.phpfreaks.com/topic/228503-arranging-an-array/#findComment-1178287
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.