wisemaar Posted January 9, 2007 Share Posted January 9, 2007 I am sure somebody must have had this problem before!!!Basically I have retrieved information from a database and the results (which are names) are stored in variables named Player_1, through to Player_11.I want to use a "counter" to loop through each record and display it.. The code I have come up with to do this is below:$Players = 11; (This could be any number between 7 &11)$i=1; // Set up a counter.while ($i<=$Players) {$a = '$Player_'.$i; echo $a;}This works except that I it displays the value of $a, ie $Player_1, where as I want to display the value of the variable $Player_1Any help would be much appreciated as I have been pulling my hair out with this, and I don'y have a lot left! Quote Link to comment https://forums.phpfreaks.com/topic/33518-using-a-variable-to-call-the-value-of-another-variable/ Share on other sites More sharing options...
marcus Posted January 9, 2007 Share Posted January 9, 2007 You're putting single quotes around it.[code=php:0]$a = "$Player_$i";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33518-using-a-variable-to-call-the-value-of-another-variable/#findComment-156855 Share on other sites More sharing options...
Ninjakreborn Posted January 10, 2007 Share Posted January 10, 2007 <?phpif ($row = mysql_fetch_array($query)) { foreach ($row['players'] as $var) { echo $var; }}?> Quote Link to comment https://forums.phpfreaks.com/topic/33518-using-a-variable-to-call-the-value-of-another-variable/#findComment-156944 Share on other sites More sharing options...
wisemaar Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks for your help, Ihave cured the problem with the following code:for ($i=1; $i<=$Players; $i++) { $a='Player_'.$i; echo $row[$a]; } Quote Link to comment https://forums.phpfreaks.com/topic/33518-using-a-variable-to-call-the-value-of-another-variable/#findComment-157452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.