Jump to content
Larry Ullman's Book Forums

While Loop Not Returning First Row


Recommended Posts

Sorry, Dark Prince, but I cannot understand what you are asking.

 

Are you saying that you made a query to the database and results were returned, but for whatever reason, the first row of the results cannot be assigned to your $row variable?

 

And to clarify the last part of your question, are you trying to output your DB results to an HTML table?

Link to comment
Share on other sites

Yes and Yes you did understand right

 

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');

echo '<tr bgcolor="' . $bg . '">

 

I ran the query manually in mysql and it shows the first results, but when viewed in a browser in html table format the first result is not returned only the ones following after.

Link to comment
Share on other sites

Dark Prince, you've been posting here long enough that it's about time you start following the forum guidelines. Look at this original post. How is anyone supposed to answer that? You don't provide any code. You don't say what versions you're using. You don't say what debugging steps you've taken and what the results were.

 

You need to read the forum guidelines before you post again and you need to abide by them if you want help.

Link to comment
Share on other sites

Thanks for cracking the whip, Larry.

 

Dark Prince, rob is right in that you have provided little to nothing for us to help you with.

Whenever I'm debugging, I start things off simple.

 

For example, in this case, the problem is that you're not getting the first value, right?

As such, before I bother trying to write an HTML table, etc., I'd be trying to figure out what's up with the value.

 

For example, I might write the following for loop:

 

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

 

echo $row['DB-column-name-here'] . '<br>';

 

}

 

Also, it just occurred to me that when you said "first result", you might be referring to the first item in the $row array, and not the first set of results output to $row.

 

Long story short, I suspect that since you're using "MYSQLI_ASSOC", either your putting the wrong string within the brackets after $row, or for some reason, you are infact getting the correct results back, but you're not outputting them to the screen properly.

Link to comment
Share on other sites

 Share

×
×
  • Create New...