Re: All records not displaying...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Dec 19, 2010, at 9:46 AM, Gary wrote:

I have an issue that the first record in a query is not being displayed. It seems that the first row in alphabetical order is not being brought to the
screen.

I have run the query in the DB and it displays the correct result, so it has
to be in the php.

I have a MySQL DB that lists beers. I have a column for 'type' of beer
(imported, domestic, craft, light). The queries:

$result = MySQL_query("SELECT * FROM beer WHERE type = 'imported' AND stock
= 'YES' ORDER by beername ");

When I run the query

if (mysql_num_rows($result) == !'0') {
   $row = mysql_fetch_array($result);

 echo '<h3>Imported Beers</h3>';
 echo '<table width="100%" border="0" cellspacing="1" cellpadding="1"
id="tableone" summary="">

 <th>Beer</th>
 <th>Maker</th>
 <th>Type</th>
 <th>Singles</th>
 <th>6-Packs</th>
 <th>Cans</th>
 <th>Bottles</th>
 <th>Draft</th>
 <th>Size</th>
 <th>Description</th>';

 while ($row = mysql_fetch_array($result)) {

echo '<tr ><td>' . $row['beername'].'</td>';
echo '<td>' . $row['manu'] . '</td>';
echo '<td>' . $row['type'] . '</td>';
echo '<td width="40">' . $row['singles'] . '</td>';
echo '<td width="20">' . $row['six'] . '</td>';
echo '<td width="40">' . $row['can'] . '</td>';
echo '<td width="20">' . $row['bottles'] . '</td>';
echo '<td width="40">' . $row['tap'] . '</td>';
echo '<td>' . $row['size'] . '</td>';
echo '<td>' . $row['descrip'] . '</td>';
'</tr>';
   }
echo '</table><br />';

}

All but the first row in alphabetical order are displayed properly.

Can anyone tell me where I am going wrong?
--
Gary

BTW, I do have a bonus question that is about javascript in this same file,
so if anyone want to take a stab at that, I'll be happy to post it.


This code will totally eliminate the first row of data.

if (mysql_num_rows($result) == !'0') {
   $row = mysql_fetch_array($result);

Fetches the first row, but is not output. Because:

 while ($row = mysql_fetch_array($result)) {

Fetches the second row before you do any output of the data.

Eliminate the first fetch_array and you're code should work fine.

BTW, if you put the <td> attributes 'width="n"' in the preceding <th> tags, you won't have to output them for each row. You should also put the units those numbers are associated with.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux