Drainy Posted January 23, 2009 Share Posted January 23, 2009 Hi, I dont know if this exists or is possible. I have the results of an SQL query saved into $result. Now the only way I can see to view this is using a while loop with fetch_assoc. However I want to save the values of each field into their own variables. Is there an easy way to do that? Failing that I am trying to put two variables together to make one.... eg; $name$i I would then incrememnt $i during the loop so each field is saved into its own variable, $name0, $name1, $name 2 etc. Any ideas? Link to comment https://forums.phpfreaks.com/topic/142184-compound-variables/ Share on other sites More sharing options...
Mark Baker Posted January 23, 2009 Share Posted January 23, 2009 $i = 0; foreach($result as $row) { $varName = 'name'.$i; $$varName = $row['name']; $varAge = 'age'.$i; $$varAge = $row['age']; $i++; } Why? Link to comment https://forums.phpfreaks.com/topic/142184-compound-variables/#findComment-744812 Share on other sites More sharing options...
Drainy Posted January 23, 2009 Author Share Posted January 23, 2009 I have a page that will allow a user to change "rates" set in the rates table. I am trying to get the page to load the current rates into the text boxes as the default value so they know what the previous rates were before editing. My issue is that I did alot with PHP many years ago but now its like learning it again and im falling down on the basics now. I have a resource in the form of $result (from the sql query) that I cant do anything with, I need all the data out of it into a usable form. Link to comment https://forums.phpfreaks.com/topic/142184-compound-variables/#findComment-744816 Share on other sites More sharing options...
Mark Baker Posted January 23, 2009 Share Posted January 23, 2009 If your code is sensibly designed, the result set from the query should be a lot more usable than a set of individual variables Link to comment https://forums.phpfreaks.com/topic/142184-compound-variables/#findComment-744818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.