Phaelon Posted May 12, 2014 Share Posted May 12, 2014 Does anyone know how I can make a variable name with partial use of another variable? while ($row = mysql_fetch_assoc($result)) { $option'.$row['number'].' = 1; } So, I would get:$option1 = 1$option2 = 1$option3 = 1I tried '$option'.$row['number'].'' = 1;, but it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/ Share on other sites More sharing options...
mac_gyver Posted May 12, 2014 Share Posted May 12, 2014 making a series of numbered variables creates a nightmare of extra code. you need to use a simple array - $option[1], $option[2], ... Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479180 Share on other sites More sharing options...
Phaelon Posted May 12, 2014 Author Share Posted May 12, 2014 (edited) No, I want to do it my way because there is a bigger picture to what I am doing which I haven't explained as it is irrelevant and I want to keep my thread simple. ... So do you know if what I want to do can be done, or are you just lecture me on what you thinks best without providing any assistance what so ever? Edited May 12, 2014 by Phaelon Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479181 Share on other sites More sharing options...
Phaelon Posted May 12, 2014 Author Share Posted May 12, 2014 What ever man... For anyone that wants to know the answer, here it is: while ($row = mysql_fetch_assoc($result)) { ${option'.$row['number']} = 1; } Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479186 Share on other sites More sharing options...
mac_gyver Posted May 12, 2014 Share Posted May 12, 2014 no one here really wants to see code you got at another help site. btw - that code is three times slower than the method i suggested, which is just one of the problems with using variable variables. Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479189 Share on other sites More sharing options...
Phaelon Posted May 12, 2014 Author Share Posted May 12, 2014 (edited) Sure they don't. The code you suggested isn't compatible with what I needed to do. I already told you this. You need to stop assuming you know other people are trying to do.. and if speeds anything to go by, I'd still be stuck if it wasn't for the other help site. You need to stop over analysing in life. I use to have this problem. Cheers. Edited May 12, 2014 by Phaelon Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479195 Share on other sites More sharing options...
Jacques1 Posted May 12, 2014 Share Posted May 12, 2014 And now you have two problems: utter ignorance and a bunch of crap code. Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479196 Share on other sites More sharing options...
Phaelon Posted May 12, 2014 Author Share Posted May 12, 2014 No, I have a working product. Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479202 Share on other sites More sharing options...
Ch0cu3r Posted May 12, 2014 Share Posted May 12, 2014 And now you have two problems: utter ignorance and a bunch of crap code. Agreed.. FYI this is what the OP is trying to achieve http://forums.phpfreaks.com/topic/288403-creating-a-single-variable-for-multiple-mysql-returns-of-the-same-data/ Quote Link to comment https://forums.phpfreaks.com/topic/288433-making-a-variable-name-with-partial-use-of-another-variable/#findComment-1479220 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.