The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
$count = 20;
while($count > 0)
{
[match up $text_20 to $count when that is 20]
$count--;
}
The problem isn't my syntax, it's actually how to get it to work!
EDIT:
Don't worry, it's just me being a mong. It's pretty obvious what I was doing wrong - one variable going up, one variable going down, I was using the wrong one! Cheers though, being able to put them variables together is really handy.
$count = 20;
while($count > 0)
{
if (isset($_POST["text_".$count])) {
$somevar=$_POST["text_".$count]);
}
$count--;
}
I think your problem is that you're relying on registered variables? ie, $text_20 being created for you when you post to the script. You shouldn't rely on this anymore, register globals is off by default in php now so eventually you're going to encounter a server that won't like your code (aside from the security risks of relying on it).
Anyway, if you just access your post data through $_POST then its easy to accomplish what you want if I understand your problem correctly.
> $count = 20;
> while($count 0)
> {
>
> [match up $text_20 to $count when that is 20]
>
> $count--;
>
> }
>
> The problem isn't my syntax, it's actually how to get it to work!
You need to put the name of the variable you want into a string.
eg:
$myvar = 'text_'.$count;
echo $$myvar;
Then the $myvar variable gets expanded by php to be 'text_20' or whatever, and that echo line above becomes echo $text_20;
It can sometimes be clearer by using curly braces, eg:
echo ${$myvar};
$count = 20;
while($count > 0)
{
[match up $text_20 to $count when that is 20]
$count--;
}
The problem isn't my syntax, it's actually how to get it to work!