Jump to content

advancing pointer with next()


niche

Recommended Posts

I currently have 22 items in a mysql database that I want to split into 3 columns of links (10 + 10 + 2).Everything works, except for the way I'm using next(). I expected next() to advance the internal pointer, but it stays at the beginning of the array. Why? Current script:

$row = mysql_fetch_array( $result );while ($counter < 10) {  echo '<a class="one" href="jf3.php">'.$row['locname'].'</a><br/>';  next($row);counter = $counter + 1; }

FYI: This works:

while ($row = mysql_fetch_array( $result )) {  echo '<a class="one" href="jf3.php">'.$row['locname'].'</a><br/>';}	

Thanks,Niche

Link to comment
Share on other sites

mysql_fetch_array() returns the result from one row. To advance to the next row, you need to do another call to mysql_fetch_array(), which would in turn give you a new array representing the next row.next() only moves the pointer of arrays. The thing is you want a new array, based on the MySQL pointer, not move the pointer of the array you already have.Your second example works, because you're making a new mysql_fetch_array() on every loop.

Link to comment
Share on other sites

boen_robot, thanks for you help. You got me to the answer.Thanks,Niche

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...