OK, Difficult to see from your pseudo code EXACTLY what it is that you want to do, but I'll take a stab anyway...
Firstly, 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>'; You must also remember that in cases where you do "limit" queries, and want to "continue" on the next page, you must remember that your result will NOT contain the "next" page's data. You will need to do another query with the new "limit" data. It *looks* like this is what you are in fact attempting in your code, just making sure... In your case, I would say the easiest is to call the page onto itself. Ie, your first query will be $sql = "whatever limit 0,6"; it will return the (maximum) 6 rows and then, on your "next" link you should include the data for the next query. Ie, create a link like this: <a href="same_page.php?limit=x&start=y">Next</a> Meaning that you call up the same page that you used to display the first query results, but you pass it different values for the start and limit numbers in the query ( x,y ). To recap, one of you biggest 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... -----Original Message----- From: Verdon vaillancourt [mailto:[EMAIL PROTECTED] Sent: Sunday, August 17, 2003 9:47 PM To: 'PHP-General' Subject: [PHP] Nestled 'while's or 'for's or 'foreach's -- I'm lost Hi, somewhat newbie warning :) 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'm limiting my result set to 6 records and want to display it as 2 rows of 3 cells with a record in each cell. I've had no trouble getting my result set, paging etc. I'm not having much luck splitting my result into 2 chunks. I've tried nestling 'while' statements with a number of arguments and either end up with no results or a loop that seemingly never ends. That lead me to looking at some other apps which seemed to use a variety of ways to achieve what I want. That lead me to looking at 'for' and 'foreach' in the php manual. And that lead me to being more confused than I was before I started ;) Sometimes there's just too many ways to skin a cat, eh! Below, I've include a rather lengthy bit of pseudo code that represents basically where I'm at now. This particular version returns no results, though I know it's just the nestled while's that are causing this. The results are there. My research makes me think that I should replace the nestled while's with 'foreach's. I was kind of hoping that before I spend a few hours trying to puzzle out how to use the 'foreach's correctly that somebody would venture an opinion as to whether or not that would be the way to go. Thanks in advance for any advice, Verdon -- pseudo code -- <?php $limitPerPage = 6 ; $initStartLimit = 0; if (!isset( $startLimit )) { $startLimit = $initStartLimit ; } $querylimit = " limit $startLimit,$limitPerPage " ; $nextStartLimit = $startLimit + $limitPerPage ; $previousStartLimit = $startLimit - $limitPerPage ; if ( $sortby != "" ) { $sorted = " order by $sortby " ; } $bareQuery = "select * from pieces order by rank"; $queryall = $bareQuery .$sorted .$querylimit; $resultall = mysql_query ($queryall); $numberall = mysql_numrows ($resultall); if ( $numberall == 0) { echo "No Records Found !" ; } else if ( $numberall > 0) { $x = 0; echo "<h2>Page of Pieces</h2>"; while ( $x < $numberall ) { // Retreiving data and putting it in local variables for each row $id = mysql_result ($resultall ,$x ,"id"); $title = mysql_result ($resultall ,$x ,"title"); $description = mysql_result ($resultall ,$x ,"description"); $thumb = mysql_result ($resultall ,$x ,"thumb"); $company = mysql_result ($resultall ,$x ,"company"); echo "<table cellspacing=\"0\">"; echo "<tr>"; while ($x >= 0 && $x < 4) { echo "<td>"; if ($thumb) { echo "thumbnail with a link"; } else { echo "text with a link"; } echo "<br /><strong>$title</strong>"; echo "<br />$company"; echo "<br />$description"; echo "</td>"; $x ++; } echo "</tr>"; echo "<tr>"; while ($x > 3 && $x < $numberall) { echo "<td>"; if ($thumb) { echo "thumbnail with a link"; } else { echo "text with a link"; } echo "<br /><strong>$title</strong>"; echo "<br />$company"; echo "<br />$description"; echo "</td>"; $x ++; } echo "</tr>"; echo "</table>"; $x ++; } // end while echo "</table><br />"; echo "<div class=\"footLinks\">"; echo "Previous links"; echo "Next links"; echo "</div>"; }// end if numberall > 0 ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php