niche Posted August 1, 2010 Share Posted August 1, 2010 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 More sharing options...
boen_robot Posted August 1, 2010 Share Posted August 1, 2010 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 More sharing options...
niche Posted August 1, 2010 Author Share Posted August 1, 2010 boen_robot, thanks for you help. You got me to the answer.Thanks,Niche Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.