Page 1 of 1

first row not printing with mysql_fetch_array

Posted: Fri Aug 22, 2008 3:35 pm
by zachrose
Hi all,

I seem to be having some trouble understanding mysql_fetch_array(). I've got a script and for some reason it seems to be skipping the first mysql result row but doing fine with every one after that.

Here's the code:

Code: Select all

 
$list_query = "SELECT first_name, last_name, students.student_id
 
FROM enrollment, students
 
WHERE enrollment.student_id = students.student_id 
AND date >= '$date_start'
AND date < '$date_end'
ORDER BY date";
 
if (!($list_result = @ mysql_query($list_query, $connection)))
    die (showerror());
$list_info = mysql_fetch_array($list_result);
if (empty($list_info))
    { echo '<tr><td class=body colspan=7 align=center>There were no registrations for this date.</td></tr>'; }
else 
    {
    echo $list_info[0];
    while ($list_info = mysql_fetch_array($list_result))  //why doesn't this return the first row?
        {
            $first_name = $list_info['first_name'];
            ...and so on assigning array elements to variables and then echoing them with formating.
 
If I sort the MySQL query by date, the earliest row doesn't print. If I sort it by first_name, Beth and Carol will print but not Albert.

I think this is a problem with mysql_fetch_array(), but I have no idea why.

Any thoughts?

Re: first row not printing with mysql_fetch_array

Posted: Fri Aug 22, 2008 5:24 pm
by jaoudestudios
You are fetching the array twice, you only need to do it once.

Line 13 is your problem!