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? Link to comment https://forums.phpfreaks.com/topic/66473-dynamically-naming-variables/ 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 Link to comment https://forums.phpfreaks.com/topic/66473-dynamically-naming-variables/#findComment-332882 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/66473-dynamically-naming-variables/#findComment-332906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.