Jump to content

Variable and While Statement


steveangelis

Recommended Posts

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

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.