Forum Moderators: coopster

Message Too Old, No Replies

While Loop causing row to skip

While Loop causing row to skip

         

Seachmall

10:15 am on Oct 21, 2007 (gmt 0)

10+ Year Member



I'm having a problem when I try to display an array within a while loop. It skips sthe first row and then continues on however I don't want it to skip the first row. I know there was a question like this posted before (I did search) but it didn't have what I was looking for.

This is what I have:


$new = mysql_query("SELECT Tabel1.*, Table2.* FROM Table1, Table2 WHERE Table1.Status = 'New' AND Table1.IdNo = Table2.IdNo ORDER BY Table1.yy, Table1.mm, Table1.dd, Table1.idNo");
$new_row=mysql_fetch_array($new);

function display_days($row,$result){

global $new;
global $new_row;

$currDay = "";
while($row=mysql_fetch_array($result))
if($currDay!=$row['day']){
<table><caption>
</caption>
<tr><th>ID Number</th><th>
Surname</th><th>
First name</th><th>
<?PHP
$currDay = $row['day'];
}
?>
<tr>
<td> <?PHP echo $row['IdNo'];?> </td>
<td> <?PHP echo $row['Sname'];?> </td>
<td> <?PHP echo $row['Fname'];?> </td>

</tr>
<?PHP

}
}
?>

<?PHP display_days($new_row,$new);?>

I believe it to be something to do with the while loop because if I view the array before the loop it displays it all but once it enters the loop it drops the first row.

Habtom

10:22 am on Oct 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only thing which seems odd in there is this line: $new_row=mysql_fetch_array($new);

Comment it out and see if you get the necessary results. The reason is you are trying to fetch array (mysql_fetch_array) twice.

I think that is the most probable reason.

Habtom

Seachmall

10:45 am on Oct 21, 2007 (gmt 0)

10+ Year Member



Thank you so much. I've been stuck on that for about two weeks. I knew it was something simple but just couldn't see it. Guess it pays to have a fresh pair of eyes (and a knowledgable pair) to look at it.

Thanks again.

Habtom

10:46 am on Oct 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are welcome.

Welcome to WebmasterWorld, Seachmall.

Seachmall

11:01 am on Oct 21, 2007 (gmt 0)

10+ Year Member



Thanks, I'll definetly be sticking around :)