/    Sign up×
Community /Pin to ProfileBookmark

PHP do, loops….

Can someone take a look at this and tell me whats wrong? I need $num to increment from 0 to totalRows_scroll.

[code=php]
<?
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));

?>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@cwilkeyauthorDec 06.2005 — If I remove the comment next to: echo $num ."<br>" it display correctly:


1

2

however once I call it from the do statement it only displays the last value (2)
Copy linkTweet thisAlerts:
@NogDogDec 06.2005 — I think you'll find the whole thing can be done much more easily in one while loop:
[code=php]
$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>";
}
[/code]
Copy linkTweet thisAlerts:
@cwilkeyauthorDec 06.2005 — Thanks NogDog!
×

Success!

Help @cwilkey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...