On Sun, 17 Aug 2003 15:47:04 -0400, I wrote: >> I'm trying to take a paged result set and divide it into two chunks for >> displaying on the page. Basically making something that looks like a typical >> thumbnail gallery... ...I've include a rather lengthy bit of pseudo code that >> represents basically where I'm at now...
Thanks David, Petre, and Curt David, this is exactly what I was so poorly trying to get at ;) I just have to consider my found result set of rows as array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') Your example renders the data in the way I was looking for. Thanks! > On 8/17/03 3:57 PM, "David Otton" <[EMAIL PROTECTED]> wrote: > $data = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); > $rowlength = 3; > > echo ("<table>"); > for ($i = 0; $i < sizeof ($data); $i += $rowlength) > { > echo ("<tr>"); > for ($j = 0; $j < $rowlength; $j++) > { > if (isset ($data[$i+$j])) > { > echo ("<td>{$data[$i+$j]}</td>"); > } else { > echo ("<td> </td>"); > } > } > echo ("</tr>"); > } > echo ("</table>"); > Petre, you were right also. I was able to get my pseudo method to work, though it was a mess ;) Your example has provided some guidance in re-thinking. Best Regards. > On 8/17/03 4:18 PM, "Petre Agenbag" <[EMAIL PROTECTED]> wrote: > ...instead of using your elaborate ways of running through the > result set and extracting the variables, use something like this: > > $sql = "whatever"; > $result = mysql_query($sql); > > echo '<table><tr><td>ID</td>...</tr> > > while ($myrow = mysql_fetch_assoc($result)) { > extract($myrow); > //or $id = $myrow[id]; etc. > ... > //construct your table here > echo '<tr><td>'.$id.'</td>...</tr>'; > ... > } > echo '</table>'; > > > ... mistakes in the pseudo code below is that you open a the <table> inside > the while and close it as well (which is fine if you want to create a table > for each row you display , BUT, you close the table again AFTER the while, > that *could* cause the HTML to freak out. So, the reason your app is not > working is probably not PHP related, but related to the fact that you are > creating erroneous HTML with your PHP. The pseudo code you are using *should* > work, although, as I stated above, there are easier and more efficient ways of > doing the same thing as per my example... > Curt, another way of looking at it. Thank You. > From: Curt Zirzow <[EMAIL PROTECTED]> > Date: Sun, 17 Aug 2003 23:24:49 +0000 > This can easily be done using the mod operator (%): > > $cols_per_page = 3; > $cols_per_page_break = $cols_per_page - 1; // just to speed the loop > > echo "<table>"; > echo "<tr><th>Col Headings....</th></tr>"; > > $counter = 0; > while($row = db_fetch_row() ) { > > $new_row = $counter++ % $cols_per_page; > if ($new_row == 0 ) { > echo "<tr>"; // open a row > } > > echo "<td>Col Data</td>"; > > if ($new_row == $cols_per_page_break ) { > // close and open a row > print "</tr>"; > } > } > > // Make sure the row was closed in case of uneven recordset. > if ( ( ($counter - 1) % $cols_per_page) != $cols_per_page_break ) { > // close and open a row > // cause we didn't close it in the loop > print "</tr>"; > } > > echo "</table>"; //close row and table > > um.. ok, so it wasnt that easy.. I made this a little more > complicated than I was expecting it to be. > > btw, this is completely untested. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php