Jump to content

Setting Variable Names Using Field names?


Petty_Crim

Recommended Posts

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];
	}
 }

Link to comment
https://forums.phpfreaks.com/topic/57978-setting-variable-names-using-field-names/
Share on other sites

U want to update the player name or just to select it.

i am not clear about ur q.

Player names are fields in my table. If I add a new player atm I have to go around updating everything that is why I want to automate it.

 

In my code above I'm trying to get the field name ie John make that into a variable with the same name ie $john and then assign a post variable as its value.

What about using an Array?

Instead of having player's names as variables:

$john

$steve

$frank

$jeff

you would have:

$player[1]

$player[2]

$player[3]

$player[4]

 

Disclaimer: it's  quarter past midnight here, syntax may not be correct. Check the PHP man pages for array usage...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.