Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query results alway 1 record short

Status
Not open for further replies.

brk1221

MIS
Joined
Jan 29, 2002
Messages
230
Location
US
Hi, the results of my SELECT on my .php page always returns one record short. It displays "There are 3 records." but only 2 will display. I've included the code from the .php file:

if ($code=="")
$sql = ("SELECT * FROM sites WHERE state='$state'");
elseif ($state=="")
$sql = ("SELECT * FROM sites WHERE code='$code'");
else
$sql = ("SELECT * FROM sites WHERE code='$code' AND state='$state'");
//echo($sql);
$result = mysql_query($sql);
if ($myrow = mysql_fetch_array($result))
$num_rows = mysql_num_rows($result);
print &quot;<p><a href=javascript:history.back(1)><font size=1>BACK</font></a></p>&quot;;
print &quot;There are $num_rows records.<P>&quot;;

print &quot;<table width=100% border=1>\n&quot;;
while ($get_info = mysql_fetch_row($result)){
print &quot;<tr>\n&quot;;
foreach ($get_info as $field)
print &quot;\t<td>&nbsp<font face=arial size=1/>$field</font></td>\n&quot;;
print &quot;</tr>\n&quot;;
}
print &quot;</table>\n&quot;;
 
How can I fix this? The data output looks fine, just one short.

Thanks
 
I remarked out the: if ($myrow = mysql_fetch_array($result))
line and it returns the correct data!!

Thanks
 
Not exactly sure why it's there - still experimenting with php. Another question, how would I put in column headings for the html table that gets generated?

Thanks
 
By looking at my above code could you get me started with the column headings, I'm getting the headings appearing in every cell!

Thanks
 
I'm switching to Socratic Method.

If you want column headings output, where should the print statement appear?

Compared to the number of times the &quot;<table>&quot; tag is output, how many times are you going to output the column headers?

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top