Name a Variable after the name of a field?

I’m having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name.

This is the code I’m using:
$result=mysql_query(“SELECT * FROM playerstats”);

while($fld = mysql_fetch_field($result))
{
if ($fld->name!=‘match_id’ && $fld->name!=‘opponent’ && $fld->name!=‘map’)
{
$fld->name=$_POST[$fld->name];
}
}

ATM if I want to add a new player I have to manually update everything, this way I wouldn’t need to.

I think you can create variable variables by using $$.

For more information check at http://www.php.net

Sponsor our Newsletter | Privacy Policy | Terms of Service