[thelist] concat two variables to be a variable n PHP

Nan Harbison nan at ladyslipperwebs.com
Sun Aug 7 10:14:06 CDT 2005


I have a temporary table that is created on the fly to show the results of a
tournament, which may have one or more rounds of play. The extract function
is used to show the results on the event results page. I set up the table to
create the number of fields needed to store the results of each round of
play, they are called round1, round2, etc.
When I am retrieving the results extracted from the table, I want to show
the scores for each round, but I am having trouble figuring out how to name
the variables on the fly. I want to do a for loop, using $i, and somehow
concatenate variables together to form the variables $round1, $round2, etc

>From the googling I have done and testing out various ways of $round.$i
where I set $round = 'round', it only makes a string called round1, and is
not holding the value from the table. I tried using $$round.$i, but that
didn't work, it still returned 31, 32, I have no idea where that came from.
I tried setting $round = ' $round ', that doesn't work either.

I tried storing all of the fields of the table in an array, but the array
can't seem to be called by $array[$i] because of the way that extract
function uses an associative array, and not a numeric one. I thought if I
set an array equal to the extracted array I could still refer to the keys of
the new array as $array[0], $array[1], but this doesn't work either.

For now I am going to use the function array_keys to get the keys to be
numerical.....maybe this is the only way to do it? Maybe there is a
completely different and simple way to go about this whole problem?

Thanks for your help.
Nan


More information about the thelist mailing list