Click to See Complete Forum and Search --> : PHP do, loops....


cwilkey
12-06-2005, 03:09 PM
Can someone take a look at this and tell me whats wrong? I need $num to increment from 0 to totalRows_scroll.


<?
for($i = 0; $i <= $totalRows_scroll; $i++) {
$num = $i;
//echo $num ."<br>";
}
do {
$title = $row_scroll['title'];
$link = $row_scroll['link'];

echo "messages[$num]=<font face='Arial'><a href='$link'>$title</a></font>";

} while ($row_scroll = mysql_fetch_assoc($scroll));

?>

cwilkey
12-06-2005, 03:11 PM
If I remove the comment next to: echo $num ."<br>" it display correctly:

0
1
2

however once I call it from the do statement it only displays the last value (2)

NogDog
12-06-2005, 03:46 PM
I think you'll find the whole thing can be done much more easily in one while loop:

$num = 0;
while($row_scroll = mysql_fetch_assoc($scroll))
{
$title = $row_scroll['title'];
$link = $row_scroll['link'];
$messages[$num++]="<font face='Arial'><a href='$link'>$title</a></font>";
}

cwilkey
12-06-2005, 04:33 PM
Thanks NogDog!