Losing first line of results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

Losing first line of results

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Losing first line of results

Post 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.
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

Re: Losing first line of results

Post by bill1one »

That makes since and worked beautifully. Thanks for the help!
Post Reply