Yea ill give that a crack cheers ardav , thanks for all your help.

I have put together a for loop echos out my search results trouble it it can only do one at the moment

is there a way to sort of do a
for each result {
echo
<table layout> so monday tues wednesday ect
for each period echo
$input = (isset($timetable)) ? $timetable

<room num>
<Slots> 1 2 3 4 5 6

Monday
Tuesday
Wednesday

<room num>
<Slots> 1 2 3 4 5 6

Monday
Tuesday
Wednesday

<pagination> 1 2 3 4 5 6

Any help with this bit would be nice

Member Avatar for diafol

I don't understand the layout. Could you do a mockup in word or something? Take a screenshot and post it here?

This is sort of it.

Member Avatar for diafol

OK, this is off the top of my head - so excuse the spaghetti code and possible typos and up-my-own-derriere possibly needless loops.

<?php
$r = mysql_query("SELECT COUNT(`room_id`) AS `count` FROM rooms");
$d=mysql_fetch_assoc($r);
$total_rooms = $d['count']; //GET number of rooms in DB

//THE INFO BELOW COULD BE TAKEN FROM A DB TABLE, although easiest to just hard code them in a config file and use as an include file.
$page = 1;				//Default page - although superfluous due to $page ternery conditional below
$no_rooms_per_page = 5;	//Display just 2 rooms per page
$num_periods = 8; 		//8 periods
$day_array('MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY');
if($total_rooms){
	$page = (isset($_GET['page']) && intval($_GET['page']) >= 1 && intval($_GET['page']) <= ceil($total_rooms/$no_rooms_per_page)) ? intval($_GET['page']) : 1; 
    $r = mysql_query("SELECT * FROM rooms ORDER BY room_id LIMIT " . (($page - 1)*$no_rooms_per_page + 1) . ", $no_rooms_per_page");
	if(mysql_num_rows($r)){
	   	while($d=mysql_fetch_assoc($r)){
			$room_array[] = $d['room_id'];
                        $room_for_loop[] = $d;
		}
		$room_string = implode(",",$room_array); //this makes a list of room_id values for this page
		$tt_res = mysql_query("SELECT * FROM timetable WHERE room_id IN ($room_string)"); // There should be a complicated multiple JOIN syntax in this
		if(mysql_num_rows($tt_res)){
			while($d_tt = mysql_fetch_assoc($tt_res)){
				$tt[$d_tt['room_id']][$d_tt['period_id']][$d_tt['day_id']] = "<ul><li>{$d_tt['course_id']}</li></ul>";
			}
		}
		$book_res = mysql_query("SELECT * FROM bookings WHERE room_id IN ($room_string)"); // There should be a complicated multiple JOIN syntax in this
		if(mysql_num_rows($book_res)){
			while($d_book = mysql_fetch_assoc($book_res)){
				$tt[$d_book['room_id']][$d_book['period_id']][$d_book['day_id']] = "<ul><li>{$d_book['booker_id']}</li></ul>";
			}
		}
		$output = "";
		foreach($room_for_loop as $rfl){
			$output .= "\n<h3>{$rfl['room_label']}</h3>"; 			
			$output .= "\n<table class=\"timetable\">\n\t<thead>";
			$output .= "\n\t\t<tr><th>DAY</th>";
			for($x=1;$x<=$num_periods;$x++){
				$output .= "\n\t\t\t<th>$x</th>";	
			}
			$output .= "\n\t\t</tr>\n\t</thead>\n\t<tbody>";
			$day = 1;
			foreach($day_array as $dayname){
				$output .= "\n\t\t<tr>\n\t\t\t<th>$dayname</th>";
				for($period=1;$period<=$num_periods;$period++){
					$output .= "\n\t\t\t<td>";
					if(isset($d_tt[$rfl['room_id']][$period][$day])){
						$output .= 	$d_tt[$rfl['room_id']][$period][$day];
					}elseif(isset($d_book[$r['room_id']][$period][$day])){
						$output .= 	$d_tt[$rfl['room_id']][$period][$day];
					}else{
						$output .= "<p><a href=\"makebookings.php?room={$rfl['room_id']}&day=$day&period=$period\">BOOK</a></p>";
					}
					$output .= "\n\t\t\t<td>";
				}
				$output .= "\n\t\t</tr>";
				$day++;	
			}
			$output .= "\n\t</tbody>\n</table>";
		}
	}else{
		"An error occurred - seems like no rooms exist for this page - strange!";	
	}
	
}else{
  echo "No rooms found in the database. Contact the admin.";		
}

//somewhere in the page:

echo $output;

?>

It'll give you an idea of how I'd approach it - possibly not the best way. Nowadays, I'd probably use OOP - to create a lesson class and then subtype that to timetable_lessons and booking_lessons, etc. But anyway...

BTW - I've used \n and \t to prettify the html output - force of habit. :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.