Jump to content

Embedded Mysql Loop


Levan

Recommended Posts

I have a do-while loop that outputs a table with a series of times down one column....
The concept is a day-planner.

In the details section each time a row is produced it checks that the mysql query I have defined doesnt have a record with that particular time.  However the  system seems to go into an infinite loop and I cannot see why...code to follow...

First code excerpt...the mysql query...
[code]<?php
mysql_select_db($database_db_connect, $db_connect);
$query_appointments = sprintf("SELECT * FROM appointment WHERE `Time` >= '%s' AND `Time` <='%s' ORDER BY `Time` ASC",$begindayunix,$enddayunix);
$appointments = mysql_query($query_appointments, $db_connect) or die(mysql_error());
$row_appointments = mysql_fetch_assoc($appointments);
$totalRows_appointments = mysql_num_rows($appointments);
?>[/code]

The next excerpt is the table creation loop and inbuilt mysql check...
[code]
</table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<?php 
do{
//simply gets the unix time for the current appointment slot and converts it.
$currentapp_array=getdate($currentapptime);
if ($currentapp_array['hours']<10){$hours="0".$currentapp_array['hours'];}else{$hours=$currentapp_array['hours'];}
if ($currentapp_array['minutes']<10){$minutes="0".$currentapp_array['minutes'];}else{$minutes=$currentapp_array['minutes'];}
?>
  <tr bordercolor="#999999" nowrap="nowrap"
  <?php //checks if its lunch time and greys out those slots.
    if ($currentapptime  > $lunchbeginunixtime AND $currentapptime < $lunchendunixtime){echo 'bgcolor="#DDDDDD"';}else{echo 'bgcolor="#FFFFFF"';} ?>
  >
  <td width="10%" align="center"><a href="createappointment.php?Time=<?php echo $currentapptime;?>"><?php echo $hours.":".$minutes;?></a></td>
<?php if ($currentapptime=$row_appointments['Time']){?>
<td width="70%"><?php echo $row_appointments['Details'];?></td>
<td width="20%"><?php echo $row_appointments['PatientID'];?></td><?php }else{ ?>
<td width="70%"></td>
<td width="20%"></td> <?php } ?>
<?php $currentapptime=($currentapptime+$appseconds);}while($currentapptime<$endtime);?>
</table>
[/code]

I assumed that once I have processed a row from my query it moves to the next row....I think I am probably wrong in that regard...I am going to reverse the loops and see if that works any tips would be great...

Lev
Link to comment
https://forums.phpfreaks.com/topic/17075-embedded-mysql-loop/
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.