/    Sign up×
Community /Pin to ProfileBookmark

‘for’ Loop Not Returning Data…

Returns ‘t2,’ as expected:

[code]
$c=1;
$thisCookie = ‘tbl’.$c;
if (isset($_COOKIE[$thisCookie]))
{
$newTable = ‘t’.($c+1);
}
else
{
$newTable = ‘cookie tbl1 was not found’;
}
echo (“<script>alert(‘”.$newTable.”‘);</script>”);
[/code]

Returns nothing (null alert), as if the ‘for’ loop is not even activated. This is [b]not[/b] expected ? :

[code]
for ($c=1; $y=”; $c++)
{
$thisCookie = ‘tbl’.$c;
if (isset($_COOKIE[$thisCookie]))
{
$newTable = ‘t’.($c+1);
}
else
{
$y=’y’;
}
}
echo (“<script>alert(‘”.$newTable.”‘);</script>”);
[/code]

I’m simply trying to create a variable one increment greater than that of the highest valued cookie (eg, if tbl4 is found, I want to create $newTable=t5). Is there something wrong with my approach/syntax???

Thank you very much for any assistance that you can provide,

bubbis

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bubbisthedogauthorJun 25.2006 — I don't know [i]why[/i] this works when the other didn't:
[code]
$y='going';
for ($d=1; $y<>'ended'; $d++)
{
$thCookie = 'tbl'.$d;
if (isset($_COOKIE[$thCookie]))
{
$newTable = 't'.($d+1);
}
else
{
$y='ended';
}
}
echo ("<script>alert('".$newTable."');</script>");
[code]
I was assuming that the default value for $y was '' (null). I know that I've figured out the issue, but could someone please inform me as to why what I had previously did not work?

Thanks,

bubbis
×

Success!

Help @bubbisthedog 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...