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
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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.