note 31179 added to control-structures.while

From: Date: Sat, 12 Apr 2003 02:54:33 +0000
Subject: note 31179 added to control-structures.while
Groups: php.notes 
Request: Send a blank email to php-notes+get-46534@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"); 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://www.php.net/manual/en/control-structures.while.php http://master.php.net/manage/user-notes.php?action=edit+31179 http://master.php.net/manage/user-notes.php?action=delete+31179 http://master.php.net/manage/user-notes.php?action=reject+31179

« previous php.notes (#46534) next »