galvin Posted December 10, 2008 Share Posted December 10, 2008 I'm probably not explaining this will, so I'll apologize ahead of time. Anway, I have a page that echos the following code (contained in $userRow) over and over for each User... $userRow = "<tr><td class=\"name\">{$users["firstname"]}" . " " . "{$users["lastname"]}<br/><img src=\"http://gdoot.com/gsfl/images/user_{$users["userid"]}.jpg\" /> <span class=\"record\">RecordPlaceHolder</span><span></span></td>"; In that last empty span, I want it to display a certain number for each user. Earlier in the code on the same page, I have a variable for each user to hold that number, such as.. $numberforuser_1 = 2 $numberforuser_2 = 4 $numberforuser_3 = 1 $numberforuser_4 = 4 $numberforuser_5 = 0 $numberforuser_6 = 2 And so on. I have each user's ID (and first name and last name) stored in the $users array. So in that last empty SPAN, I assumed I could put "<span>$numberforuser_{$users["userid"]}</span>" and I would think for each User it would output $numberforuser_X and therefore, if, for example, it was "$numberforuser5," it would output "0" in that SPAN since above, $numberforeuser_5 = 0. But it's not doing that. It seems like it won't let you call something first to get PART of a variable and then have that varible's value actually output. I'm using the same thinking as you can see earlier that has "http://gdoot.com/gsfl/images/user_{$users["userid"]}.jpg" and that pulls in each user's ID fine and displays the proper image. But since I'm putting a VARIABLE instead of a URL, it's not working. Assuming that makes sense, which it probably doesn't, anyone know what I'm doing wrong, or another way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/136434-solved-trouble-outputting-a-variable/ Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 I'm a little lost, so this may get you lost... so possibly just ignore me. $numberforuser[1] = 2 $numberforuser[2] = 4 $numberforuser[3] = 1 ... use $numberforuser[$users["userid"]] but I really am lost on what you are looking for exactly Quote Link to comment https://forums.phpfreaks.com/topic/136434-solved-trouble-outputting-a-variable/#findComment-712083 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 ${'numberforuser_' . $users["userid"]} Quote Link to comment https://forums.phpfreaks.com/topic/136434-solved-trouble-outputting-a-variable/#findComment-712097 Share on other sites More sharing options...
galvin Posted December 11, 2008 Author Share Posted December 11, 2008 Your format worked perfectly, Thorpe! Thanks to you both for helping me! Quote Link to comment https://forums.phpfreaks.com/topic/136434-solved-trouble-outputting-a-variable/#findComment-712119 Share on other sites More sharing options...
trq Posted December 11, 2008 Share Posted December 11, 2008 I'll let you know though that using variable variables (my method) is far slower and IMO harder to read than simply using an array (Brian W's method). Quote Link to comment https://forums.phpfreaks.com/topic/136434-solved-trouble-outputting-a-variable/#findComment-712131 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.