Re: problem with for loop...help....

From: Date: Fri, 15 Sep 2000 01:43:06 +0000
Subject: Re: problem with for loop...help....
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16883@lists.php.net to get a copy of this message
On Fri, 15 Sep 2000, Shane McBride wrote: > > I am trying to format a table with 2 columns and as many rows as the array requires, but with > the following code it appears that the for loop is not working... > > I have looked all over for a bertter understanding of the for loop. Any ideas here what is > wrong with this code.... > > echo "<table border=1>"; > while($row1 = mysql_fetch_array($sql_result1)) { > $item_type = $row1["html_value"]; > $sql_count = "SELECT COUNT(item_type) ourcount FROM products WHERE item_type = > \"$item_type\""; > $sql_count_result = mysql_query($sql_count, $connection); > echo "<tr>"; > for ($i = 0; $i < 1; $i++) { > while($row1 = mysql_fetch_array($sql_count_result)) { > $item_count = $row1["ourcount"]; > echo "<td>$item_type ($item_count)</td>"; > } > } > echo "</tr>"; > } > echo "</table>"; > Use the modulus operator in your inner loop; count the number of records processed and when you reach a multiple of two, start a new row in the table, otherwise just start a new cell. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#16883) next »