Hi,
Does anyone know how to get a variable in a variable name?
Thanks,
Chris
Variable in a variable name
Moderator: General Moderators
You might want to look into arrays.
Code: Select all
$One = 1;
$Two = 2;
$Data = array();
$Data[$One] = "Whatever";
$Data[$Two] = $Anything;
echo $Data[1]; // prints WhateverIt's explained in the manual... http://be.php.net/manual/nl/language.va ... riable.php
-
phpgeek2006
- Forum Newbie
- Posts: 2
- Joined: Sun Mar 05, 2006 6:34 am
Use a while loop:
I'm not sure this is what you want though. There is probably an easier way to do what you are trying to accomplish. You will need to research the php array functions.
You could also use array_push()
Code: Select all
$Resource = mysql_query("select `field1`, `field2` from `table`",$Link_ID);
$Counter = 0;
$Records = array();
while ($Data = mysql_fetch_assoc($Resource)) {
$Records[$Counter] = $Data;
$Counter++;
}
// then you can get it back out
echo $Records[0]['field1'];You could also use array_push()