Jump to content

can't print all rows in db


Bazzaah

Recommended Posts

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>';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.