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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While loop returning records 2 and higher. Where's the first?

Status
Not open for further replies.

DeZiner

Programmer
May 17, 2001
815
US
while ($myrow = mysql_fetch_array($result)) {

printf (&quot;<a href='calldetail.php?id=%s' target='_blank'>%s</a> <br>&quot;, $myrow[7],$myrow[5]);

Using this, the first record is not returned. Only records 2 and higher that are in the databse.

Any thoughts. If you need more info, please let me know.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Odds are your query is what's actually eliminating your first two rows, or you have some lines between your...
Code:
$result=mysql_query($sql) or die(mysql_error());

line.

I would suggest dumping your $sql variable (hoping you're using one) to the browser, cut'n'paste it to something like phpmyadmin, and verify that it's returning what you think it is.

I would also suggest a simple function like...
Code:
function showResults($sql) {
  $result=mysql_query($sql) or die(mysql_error());
  echo '<pre>';
  while ($row=mysql_fetch_assoc($result)) {
    print_r($row);
  }
}

Which could be used to show you exactly what's being returned.
 
Also:
For clarity I would recommend to use mysql_fetch_assoc().
The resulting array is keyed by the column names. Then you can use $myrow['mycolumn'] instead of $myrow[7] which doesn't tell anything about what's in there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top