View Full Version : Variable array with data from MySQL

01-10-2010, 01:57 PM

I'm an hobby-programmer in PHP and MySQL that has run into a problem.
I've been reading about variable variables in PHP, but can't get it to work for the specific case I need it to. Here's the set-up:

I have a table named participants. The participants have one line each, but are mostly paired up in couples. This is done by a column named id - so two lines have the same value (1, 2, 3...) in the id-column.
I then query the database (aocuserlogin is a cookie set by a simple loginscript)
$qloadarray = mysql_query("SELECT * FROM participants WHERE (id='$aocuserlogin')");
while ($rloadarray = mysql_fetch_array($qloadarray, MYSQL_ASSOC)) {
$loadedarray = array($rloadarray[firstcolumn],$rloadarray[secondcolumn],$rloadarray[thirdcolumn]);

Since the while-loop is going to run twice I want to set the variable for the array to a name from the specific row that is running.
I mean I want the variable to be named as the value in the fourth column of the active row - does that make sense?

I have been trying something like
$$rloadarray[fourthcolumn] = array(...
but this doesn't work.
I've also tried
${$rloadarray[fourthcolumn]} = array(...
Which doesn't work either...

Does someone have an idea?

Please ask if you need additional information - it's hard to explain...

Thanks a million!!!

01-10-2010, 08:54 PM
$a[$rloadarray[fourthcolumn]] = array($rloadarray[firstcolumn],$rloadarray[secondcolumn],$rloadarray[thirdcolumn]);


Not exactly what you wanted, but easier to keep track of in my opinion.