Jump to content

Loop


swamp

Recommended Posts

Can someone help me with this loop?

 

Its just printing out the first item 10 times instead of looping through.

 

Thanks

 

$res =& $db->query('SELECT id, title FROM table');

 

$res->fetchInto($row, DB_FETCHMODE_ASSOC);

 

for ($i=0; $i < 10; $i++) {

 

?>

  <p><a href="/page/?item=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></p>

 

<?php } ?>

Link to comment
https://forums.phpfreaks.com/topic/163633-loop/
Share on other sites

Edit: Is it really necessary to use those classes? If not you can just use:

 

$result = mysql_query('SELECT id, title FROM table LIMIT 10');
while($row = mysql_fetch_assoc($result))
{
     echo '<p><a href="/page/?item=' . $row['id'] . '">' . $row['title'] . '</a></p>';
}

Link to comment
https://forums.phpfreaks.com/topic/163633-loop/#findComment-863386
Share on other sites

Can someone help me with this loop?

 

Its just printing out the first item 10 times instead of looping through.

 

Thanks

 

$res =& $db->query('SELECT id, title FROM table');

 

$res->fetchInto($row, DB_FETCHMODE_ASSOC);

 

for ($i=0; $i < 10; $i++) {

 

?>

  <p><a href="/page/?item=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></p>

 

<?php } ?>

 

Your fetch function likely only fetches one row at a time.  You'll need to call that function 10 times to get 10 different rows of data.

Link to comment
https://forums.phpfreaks.com/topic/163633-loop/#findComment-863388
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.