Zepo. Posted October 14, 2007 Share Posted October 14, 2007 $con=mysql_query("SELECT name,value FROM configuration"); while(list($name,$value)=mysql_fetch_row($con)){ $config[$name] ='$value'; } Is This Possible? Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/ Share on other sites More sharing options...
kenrbnsn Posted October 14, 2007 Share Posted October 14, 2007 Yes, except you don't want the single quotes around $value. Ken Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369426 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 Well im trying to define $config[namehere] to the value but it's not working for some odd reason. Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369427 Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 $con=mysql_query("SELECT name,value FROM configuration"); while(list($name,$value)=mysql_fetch_row($con)){ $config[$name] ='$value'; } Well, it's interesting that you would use the list variable to do it (ironically). My way of doing it, since it seems much simpler (and I've honestly never understood list() function itself or its purpose) would be the following: $con=mysql_query("SELECT name,value FROM configuration"); $config = array(); while($row=mysql_fetch_array($con)){ $name = $row['name']; $value = $row['value']; $config[$name] = $value; } That seems to be a little bit better for me to understand, I honestly don't like/understand list();. Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369429 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 Ok so i did this but no-go $con=mysql_query("SELECT name,value FROM configuration"); while(list($name,$value)=mysql_fetch_row($con)); foreach(mysql_fetch_row($con) as $key => $value) { $config[$name] = $value; } Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369432 Share on other sites More sharing options...
Zepo. Posted October 14, 2007 Author Share Posted October 14, 2007 And krats g is the winner! Thank you sir. Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369434 Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 TYVM :-D Link to comment https://forums.phpfreaks.com/topic/73228-solved-loop-question/#findComment-369436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.