/    Sign up×
Community /Pin to ProfileBookmark

Echo on last time through the loop

I need to print something to the screen the last time through the loop. My only problem is that I don’t always know which time is going to be the last. It usually shows five records at a time but it could be anything < 5.

Thanks,
[url]maddDidley.com[/url]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 11.2005 — Tough one to answer without knowing what type of loop, what needs to be echoed, exactly when it needs to be echoed in relation to any other output generated by each loop iteration, etc.
Copy linkTweet thisAlerts:
@bokehAug 11.2005 — As posted above it is hard to know what you are doing but the easiest way I can think of is echo it after you escape the loop. For example:
[code=php]while(something or other){
extract($row);
$echo_last_one = $row['key'];
}
echo $echo_last_one;[/code]
Copy linkTweet thisAlerts:
@bathurst_guyAug 11.2005 — Loop {

}

echo "Some text";

or

echo $var[count($var - 1)];


depends on what you want
Copy linkTweet thisAlerts:
@bokehAug 11.2005 — miss post
Copy linkTweet thisAlerts:
@ShrineDesignsAug 11.2005 — try[code=php]<?php
$last = key(last($array));
@reset($array);

while(list($k, $v) = each($array))
{
// ...

if($last == $k)
{
echo $v;
}
}
?>[/code]
Copy linkTweet thisAlerts:
@madddidleyauthorAug 11.2005 — As posted above it is hard to know what you are doing but the easiest way I can think of is echo it after you escape the loop. For example:
[code=php]while(something or other){
extract($row);
$echo_last_one = $row['key'];
}
echo $echo_last_one;[/code]
[/QUOTE]




I tried that but I need it to be in the loop because I need to echo a link with an Id attached to it.
Copy linkTweet thisAlerts:
@bokehAug 11.2005 — Well why can't you do this:
[code=php]while(something or other){
extract($row);
$id = $row['id'];
}
echo '<a href="somepage.php?key='.$id.'">'.$id.'</a>';[/code]
Copy linkTweet thisAlerts:
@madddidleyauthorAug 12.2005 — I don't know. I tried but something was screwy. I'll try it again this weekend.
×

Success!

Help @madddidley 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.17,
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,
)...