Help - Search - Members - Calendar
Full Version: Populating A Select List
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
The Seventh Hokage
i want to populate a select list with info from my database. however, i need to populate the list with only one of the categories in the table.

@@@/Name/Number
@@@/Vegeta/0ver 9000
@@@/Goku/ 100k

How would i code it so that the names appear on the select list?

CODE
foreach($DBInfo as $v)
{
echo "<option value='$v'>$v</option>";


}
echo "</select>"."</br></br>";


that's all i have so far.
Ed
Split it by '/':

CODE
foreach($DBInfo as $v)
{
   if(!substr_count($v, '/') == 3)
      continue;

   list($a,$b,$c) = explode('/', $v);
}


$b would hold your name (what I presume is the name), you should name the variables to something more contextual though.
The Seventh Hokage
QUOTE(Ed @ Oct 16 2009, 08:18 PM) *
Split it by '/':

CODE
foreach($DBInfo as $v)
{
   if(!substr_count($v, '/') == 3)
      continue;

   list($a,$b,$c) = explode('/', $v);
}


$b would hold your name (what I presume is the name), you should name the variables to something more contextual though.


that reads like greek to me. explanation for the win?
Ed
The manual makes it pretty self explanatory:

CODE
if(!substr_count($v, '/') == 3)

Ensure there's 3 /'s to ensure list can assign all.

http://php.net/substr-count

CODE
list($a,$b,$c) = explode('/', $v);


Assign offset, 0, 1 and 2 to variables $a, $b and $c.

http://php.net/list
http://php.net/explode
The Seventh Hokage
i'm not trying to seperate the info in the array.
all im trying to do is list all the entries in the table from one column into a select list.

since the number will vary with the size of the table, im not sure how the finite code will work for the infinite condition.

example of the tables:
Click to view attachment

the select list i'm trying to populate:
Click to view attachment

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.