steveangelis Posted February 13, 2010 Share Posted February 13, 2010 I am attempting to setup something like this and it will not work and for the sake of how the rest of the site code is, this is how it needs to be done. while ($getinfo = mysql_fetch_array($queryinfo)) { $list = $list + "<option>".$getinfo[name]."</option>"; } $final_list = $list; On a seperate page the variable $final_list needs to be echoed with all of the entries in the database that met predetermined variables echoed into a form <select> </select> like this. Does anyone know why when I echo $final_list I am getting either no entries or only one entry? Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/ Share on other sites More sharing options...
jl5501 Posted February 13, 2010 Share Posted February 13, 2010 $list = $list + "<option>".$getinfo[name]."</option>"; should be $list = $list + "<option>".$getinfo['name']."</option>"; Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011581 Share on other sites More sharing options...
steveangelis Posted February 13, 2010 Author Share Posted February 13, 2010 My bad, that was in the code. I hand typed that out here on these forums. Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011583 Share on other sites More sharing options...
steveangelis Posted February 13, 2010 Author Share Posted February 13, 2010 After toying around my current code is this: while ($getinfo = mysql_fetch_array($queryinfo)) { $list = "<option>".$getinfo['username']."</option>"; $list2 = $list + $list2; } $final_list = $list2; If I echo $list I get the first entry only while if I echo $final_list I get none. Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011597 Share on other sites More sharing options...
steveangelis Posted February 13, 2010 Author Share Posted February 13, 2010 Ok I have decided to completely redo the code and make it a function... I think function option_list() { $queryinfo = mysql_query("select * from user WHERE FIND_IN_SET('220', membergroupids)"); while ($getinfo = mysql_fetch_array($queryinfo)) { echo "<option>".$getinfo['username']."</option>"; //$list2 = $list + $list2; } } $final_list = option_list(); I was hoping this would work, and it does to a point. Instead though of echoing the values when I want them to though, they are showing them off at the top of the page before any other code. Anyone know why? Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011610 Share on other sites More sharing options...
trq Posted February 13, 2010 Share Posted February 13, 2010 + is the addition operator, your looking to concatenate two strings together, not add two numbers. $list = ''; while ($getinfo = mysql_fetch_array($queryinfo)) { $list .= "<option>" . $getinfo['name'] . "</option>"; } $final_list = $list; Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011612 Share on other sites More sharing options...
steveangelis Posted February 13, 2010 Author Share Posted February 13, 2010 That did it thank you Link to comment https://forums.phpfreaks.com/topic/191927-variable-and-while-statement/#findComment-1011614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.