next/prev buttons works4 1query - making it work for 5querys

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
austint01
Forum Newbie
Posts: 1
Joined: Sat Apr 02, 2005 11:27 am
Location: leeds

next/prev buttons works4 1query - making it work for 5querys

Post by austint01 »

I am doing a booking system which (on this page) displays some booking records in a table. Its constructed with 5arrays, mon - fri. Using 5queries, one for monday, one ofr tues etc...

now Im making a next/previous buttons at the bottom (next shows a week later, prev, a wk b4). I have it working for one query, now Im trying to get it to work for my 5

I have put in an example query which works on its own called $query, but i'd like to make the script work for $mondayres, $tuesdayres etc...

here the code striped down

Code: Select all

//work out some date stuff
//work out $monday, tues etc..

/*=====================START NEXT/PREV=================*/
/*=====================================================*/

//get $_GET['start'];
$start = $_GET['start'];
//if start doesnt exist, put it = 0
if(!isset($start)) $start = 0;

//perform query
$query = "SELECT * FROM booking WHERE roomname = 'room14' AND period = '1' LIMIT " . $start . ", 10";
$result = mysql_query($query);

/*====================DISPLAY INFO====================*/

//monday
//query for booking that belong to the roomname specified by user (clicked on a link) and where date = monday
$mondayres = mysql_query("SELECT * FROM booking WHERE roomname = '".$getdbroom."' AND `datebooked` = '$monday' ");

for ($i=0;$i<mysql_num_rows($mondayres); $i++)
{

$row = mysql_fetch_assoc($mondayres);
if ($row['username'] == 'timetabler')
{
//link for the booking form
$mon[$row['period']] = '<a href="book2.php?roomname='.$row['roomname'].'&datebooked='.$row['datebooked'].'&period='.$row['period'].'">
t: <br />
c: BOOKABLE<br />
s: 
<input type="hidden" name="period" value="'.$row['period'].'">
<input type="hidden" name="datebooked" value="'.$row['datebooked'].'">
<input type="hidden" name="roomname" value="'.$row['roomname'].'">
</a>';
}
else
{
$mon[$row['period']] = 't: '.$row['username'].' <br> '.'c: '.$row['classname'].' <br> '.'s: '.$row['subject'];  
}
}

//tues..

//wed.....

<table>
print '<tr><td bordercolor="#eeeeee">mon</td>';
foreach ($mon as $period)
{
print '<td bordercolor="#999999">'.$period.'</td>';
}
print '</tr>'; 

//print for tues, wed, thurs etc..

/*================END OF DISPLAY INFO=================*/

$query = "SELECT count(*) as count FROM booking";
$result = mysql_query($query);

$row = mysql_fetch_array($result);
$numrows = $row['count'];

if($start > 0) {
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?start=" . ($start - 7) . "\">Previous</a>";
} else {
echo 'Previous';
}

echo '&nbsp&nbsp&nbsp';

if($numrows > ($start + 5))
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?start=" . ($start + 7) . "\">Next</a>";


/*=============END OF START NEXT/PREV=================*/
/*====================================================*/
thanks
Post Reply