Dynamic Variables with a counter
| From: | Real GM Webmaster | Date: | Tue, 12 Sep 2000 02:58:43 +0000 |
| Subject: | Dynamic Variables with a counter | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16268@lists.php.net to get a copy of this message | ||
Hi,
I am trying to improve my code and remove the many similar if statements.
Currently I have over 200 if statements in a very detailed and complex page that does many different
checks.
These are in the following format:
$result = mysql_query("SELECT * FROM blah WHERE playerid = '$p101' ORDER BY
player_team, lastname");
if ($row = mysql_fetch_array($result)) {
........
};
$result = mysql_query("SELECT * FROM nbaplayers WHERE playerid = '$p102' ORDER BY
player_team, lastname");
if ($row = mysql_fetch_array($result)) {
....
}
through to p125, then it repeats from p201 to p225, p301 to p325, p401 through to p425.
What I am now trying to do is have a counter, counter1, which starts at 101 for the first section.
Having a while statement, I could then remove 24 of these if statements (the insides of these are
fairly long for formatting the output), and I would have to add the $p to the counter in the hope of
it giving me the player id. (value currently assigned to $p101, $p102, etc).
I have tried a number of different things, all without success.
Some of the things I have tried are below:
$counter1=101;
$value=$("p".$counter1);
OR
$counter1=101;
$value1="p".$counter1;
$value="$".$value1;
These are probably the closest two, but both just give me a string $p101 and not a variable.
Has anybody got an idea how I could use a counter to demonstrate a variable name that already has a
value assigned?
Thank you for your time.
Michael
Webmaster
Real General Manager, Inc.
http://www.realgm.com