Jump to content


Photo

Embedded Mysql Loop


  • Please log in to reply
3 replies to this topic

#1 Levan

Levan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 09 August 2006 - 10:17 PM

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...
<?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);
?>

The next excerpt is the table creation loop and inbuilt mysql check...
 </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>

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

#2 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 10:36 PM

Can I assume that $appseconds is defined?
Make a donation to phpfreaks. They need your help![br][br]

#3 Levan

Levan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 09 August 2006 - 10:51 PM

Yep the table works fine if you remove the are outputting the mysql data
Appseconds is defined as 900.

#4 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 10:59 PM

That took me awhile to find :)

$currentapptime=$row_appointments['Time']

should be two "=="
Make a donation to phpfreaks. They need your help![br][br]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users