Page 1 of 1

Losing first line of results

Posted: Wed Mar 12, 2008 2:56 pm
by bill1one
I'm using the following code to display results from my database:

Code: Select all

$sql = "SELECT name, description, url, subject FROM tblname INNER JOIN tbllink ON tblname.nmid = tbllink.nmid INNER JOIN tblsubject ON tbllink.sbid = tblsubject.sbid WHERE tblsubject.sbid = $id ORDER BY name";
 
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
 
echo mysql_result($result,$i,'subject');
 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  echo   "<dt><a href={$row['url']} target='_new'>{$row['name']}</a></dt>" .
         "<dd>{$row['description']}</dd>";
}
This should result in a list of names with the subject heading above. I get the subject heading and the list of names, but the first name in the list is also missing.
Why is this happening?

Thanks for any help or suggestions.
Bill

Re: Losing first line of results

Posted: Wed Mar 12, 2008 3:00 pm
by Zoxive
mysql_result is returning the first row, so when you then go and loop threw $result it knows you already output the first row. So you need to either remove this, or reset it.

mysql_data_seek()

So putting

Code: Select all

mysql_data_seek($result,0);
before your loop should work.

Re: Losing first line of results

Posted: Wed Mar 12, 2008 3:40 pm
by bill1one
That makes since and worked beautifully. Thanks for the help!