Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Sorting By The Days Of The Week.


No replies to this topic

#1 Howlin1

    Newbie

  • Kontributors
  • Pip
  • 1 posts

Posted 13 August 2011 - 11:02 PM

Hello,
I am wondering is there any way to sort a list by the days of the week (i.e. it should list Monday, Tuesday, Wednesday, Thursday and Friday)?
I am trying to make a kinda of timetable of free rooms in a building and list the weekdays (Monday - Friday), Floors (Ground, first and second) and then the time (9 am until 4pm, but I have that solved by using the 24 hour time).

Ideally what I want is to call the free rooms table for all the days/time etc of rooms that are free, and sort that list by the day of the week and then sort that result by the floor (but keeping Monday first).

What I have at the moment is:
$result= mysql_query( "SELECT * FROM free_rooms ORDER BY Day, Floor, Time ASC") or die("SELECT Error: ".mysql_error());

        echo '<p>This is a list of all the rooms that are free and on what day.</p>
	<table border="1" width="400">
	<tr align="center">
	<td><b>Day</b></td>
	<td><b>Floor</b></td>
	<td><b>Room</b></td>
	<td><b>Time</b></td>
	</tr>';

	while ($get_info = mysql_fetch_row($result))
	{
        print '<tr align="center">
	<td><b>' . $get_info[1] . '</b></td>
	<td>' . $get_info[4] . '</td>
	<td>' . $get_info[2] . '</td>
	<td>' . $get_info[3] . ':15</td>
	</tr>';	
	}
	print '
        </table>';
	mysql_close($link);
        ?>

(I'm assuming the get_info is a 2d array) So what I would need to do is to sort the get_info[1] array so Monday is first, Tuesday, Wednesday, Thursday and finally Friday. Then sort the floor (get_info[4]) by Ground, First and Second, while keeping Monday first.

On the order by clause I did try putting in ('Monday') for the day, but it only brought one or two of the Mondays to the top. I don't know enough about php (I'm a novice really) to do what I would like to do.

Is there anyway that what I want done, can be done (wholly or partially)?

Attached Files






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users