squiggerz Posted August 24, 2007 Share Posted August 24, 2007 Ok, I'm pulling values from a db, the values are all domain names. Is there any way after pulling them in with a while loop, that I can define a variable name as the value of what I have pulled? $query = "SELECT city FROM cities ORDER BY city"; $results = mysql_query($query); while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) { $thisiswhereIwantTheValueToGo = $row['city']; } I understand that the above will make the value of the variable = to the $row['city'], is there any way I can dynamically create the variable name based on that same value? Quote Link to comment Share on other sites More sharing options...
vijayfreaks Posted August 24, 2007 Share Posted August 24, 2007 hi you can do this with the following: while (list($city) = mysql_fetch_row($result)) { // $city is ur same name var where we've different value row wise } Regards, Vijay Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 Variable variables?: <?php $query = "SELECT city FROM cities ORDER BY city"; $results = mysql_query($query); while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) { $$row['city'] = $row['city']; } ?> Quote Link to comment 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.