Bazzaah Posted February 2, 2012 Share Posted February 2, 2012 Hi I have this code to echo th econtents of a table, which contains 100 rows. I want to be able to display all 100 rows. The problem is that it displays 99 (it excludes the first). I've tried to backtrack to reconstruct the code to find out where the error is but no joy. Any ideas? Thanks in advance! .... // get all entries from table $sql = "SELECT * FROM 100words ORDER BY word_id"; $result = mysqli_query($dbc, $sql); $r = mysqli_fetch_row($result); //print table entries to screen in columns echo '<div id="container">'; // results presented in html table 5 columns, 20 rows per page echo '<div id="outerbox">'; echo '<div class="innerbox">'; echo '<table class="centerresults" border="0">' . "\n"; echo '<td>'; $i = 0; $max_columns = 5; while ($list = mysqli_fetch_assoc($result)) { extract($list); // open row if counter is zero if($i == 0) echo '<tr>' . "\n"; echo '<td width="150px"><a href="word.php?w=' . $list['word'] . '">' . $list['word'] . "</a></td> \n "; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo '</td>' . "\n"; $i=0; } // END if(++$i == $max_columns) { } // END while (!empty($myArray)) { //} END while ($list = mysql_fetch_array($result)) { //END if($i < $max_columns) { echo '</tr>' . "\n"; echo '</table>' . "\n"; echo '</div>'; echo '</div>'; Quote Link to comment https://forums.phpfreaks.com/topic/256250-cant-print-all-rows-in-db/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 2, 2012 Share Posted February 2, 2012 You are fetching and discarding the first row from the result set before the start of your loop with the following line of code - $r = mysqli_fetch_row($result); Why do you have that line in your code at all? I ask this because this (missing the first row of data) is a fairly common problem and even before I saw your code, knew what was likely causing the symptom. You should know why each line is in your code (you put it there after all) and what each line of code is contributing toward the goal you are trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/256250-cant-print-all-rows-in-db/#findComment-1313650 Share on other sites More sharing options...
Bazzaah Posted February 2, 2012 Author Share Posted February 2, 2012 Indeed - I'd seen you give this answer in another thread. I thought it was there to separate the results into rows so that the $list['word'] would work. I'd been deleting some superfluous code and notes from the script and should have kept trimming! Thanks, though - all sorted! Quote Link to comment https://forums.phpfreaks.com/topic/256250-cant-print-all-rows-in-db/#findComment-1313653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.