note 31179 modified in control-structures.while by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:55:11 +0000 |
| Subject: | note 31179 modified in control-structures.while by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80033@lists.php.net to get a copy of this message | ||
Using the ":" and endwhile; in lieu of the curly braces allowed me to nest an if else
condition within the while statement as in the following:
//Sets $count at 1 initially
$count=1;
//Loads thumbnail images in table 3 columns wide, select images to load
$result = mysql_query("SELECT URLImage, FileName, URLThumb, FileNameThumb, DatePhotographed,
Comment FROM PLANTS, WEBIMAGES WHERE WEBIMAGES.PID='$PID' and
WEBIMAGES.PID=PLANTS.PID");
<?php
while ( $row = mysql_fetch_array($result) ) :
//Check to see if this is 3rd image and if so, close the table row and reset the count to 1
if ($count==3){
echo('<TD><A HREF="' . $row['URLImage'] . '' .
$row['FileName'] . '">');
echo('<IMG SRC=' . $row['URLThumb'] . '' .
$row['FileNameThumb'] .' ALT="Click to see full sized
image"></A><br>');
echo('<center><FONT SIZE=-1>DATE: ' . $row['DatePhotographed'] .
'<br>' . $row['Comment'] .
'</center></font><br></TD></TR><TR>');
$count=1;
//If this is not the 3rd image, add the image in the table and add 1 to the count
}else{
echo('<TD><A HREF="' . $row['URLImage'] . '' .
$row['FileName'] . '">');
echo('<IMG SRC=' . $row['URLThumb'] . '' .
$row['FileNameThumb'] .' ALT="Click to see full sized
image"></A><br>');
echo('<center><FONT SIZE=-1>DATE: ' . $row['DatePhotographed'] .
'<br>' . $row['Comment'] .
'</center></font><br></TD>');
$count++;
}
endwhile;
?>
It would not work nested within the curly braces of the while conditional.
--was--
Using the ":" and endwhile; in lieu of the curly braces allowed me to nest an if else
condition within the while statement as in the following:
//Sets $count at 1 initially
$count=1;
//Loads thumbnail images in table 3 columns wide, select images to load
$result = mysql_query("SELECT URLImage, FileName, URLThumb, FileNameThumb, DatePhotographed,
Comment FROM PLANTS, WEBIMAGES WHERE WEBIMAGES.PID='$PID' and
WEBIMAGES.PID=PLANTS.PID");
while ( $row = mysql_fetch_array($result) ) :
//Check to see if this is 3rd image and if so, close the table row and reset the count to 1
if ($count==3){
echo('<TD><A HREF="' . $row['URLImage'] . '' .
$row['FileName'] . '">');
echo('<IMG SRC=' . $row['URLThumb'] . '' .
$row['FileNameThumb'] .' ALT="Click to see full sized
image"></A><br>');
echo('<center><FONT SIZE=-1>DATE: ' . $row['DatePhotographed'] .
'<br>' . $row['Comment'] .
'</center></font><br></TD></TR><TR>');
$count=1;
//If this is not the 3rd image, add the image in the table and add 1 to the count
}else{
echo('<TD><A HREF="' . $row['URLImage'] . '' .
$row['FileName'] . '">');
echo('<IMG SRC=' . $row['URLThumb'] . '' .
$row['FileNameThumb'] .' ALT="Click to see full sized
image"></A><br>');
echo('<center><FONT SIZE=-1>DATE: ' . $row['DatePhotographed'] .
'<br>' . $row['Comment'] .
'</center></font><br></TD>');
$count++;
}
endwhile;
It would not work nested within the curly braces of the while conditional.
http://php.net/manual/en/control-structures.while.php