scarhand Posted November 14, 2008 Share Posted November 14, 2008 is this possible? example: <?php $sql = mysql_query("SELECT * FROM table"); while ($row = mysql_fetch_array($sql)) { foreach ($field as $value) { $$value = $row[$value]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132717-foreach-mysql-field-value-from-selection/ Share on other sites More sharing options...
JonnoTheDev Posted November 14, 2008 Share Posted November 14, 2008 $field is not an array Quote Link to comment https://forums.phpfreaks.com/topic/132717-foreach-mysql-field-value-from-selection/#findComment-690189 Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2008 Share Posted November 14, 2008 If we assume you actually meant - foreach ($row as $key => $value) { $$key = $row[$key]; } Yes it will do something, but all the variables created will be overwritten on each iteration of your outer while() loop. And since $row['your_column_name'] is a perfectly good variable to use inside of any code in the while() loop to process the data, doing what you are asking is just wasting time and memory to create the variable variables. Quote Link to comment https://forums.phpfreaks.com/topic/132717-foreach-mysql-field-value-from-selection/#findComment-690203 Share on other sites More sharing options...
scarhand Posted November 14, 2008 Author Share Posted November 14, 2008 $field is not an array I was using it as an example to show people what I am trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/132717-foreach-mysql-field-value-from-selection/#findComment-690205 Share on other sites More sharing options...
scarhand Posted November 14, 2008 Author Share Posted November 14, 2008 If we assume you actually meant - foreach ($row as $key => $value) { $$key = $row[$key]; } Yes it will do something, but all the variables created will be overwritten on each iteration of your outer while() loop. And since $row['your_column_name'] is a perfectly good variable to use inside of any code in the while() loop to process the data, doing what you are asking is just wasting time and memory to create the variable variables. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/132717-foreach-mysql-field-value-from-selection/#findComment-690206 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.