Zymic Forums

Webmaster resources

Zymic IRC Server

Chat in real time at irc.zymic.com - Learn More

Welcome

Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.

In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.

left Zymic Webmaster ForumsWeb Design & DevelopmentServer Side ScriptingPHP right
  Closed Topic Start new topic
left right
The Seventh Hoka...
post Oct 16 2009, 06:27 PM
Post #1


Member
**

Group: Members
Posts: 90
Joined: 29-May 09
Member No.: 97,073



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.
Go to the top of the page 
 
  + Quote Post
Ed
post Oct 16 2009, 08:18 PM
Post #2


Outrageously Uber Ninja
*******

Group: Administrators
Posts: 2,831
Joined: 11-March 07
From: UK
Member No.: 9



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.
Go to the top of the page 
 
  + Quote Post
The Seventh Hoka...
post Oct 16 2009, 09:30 PM
Post #3


Member
**

Group: Members
Posts: 90
Joined: 29-May 09
Member No.: 97,073



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?
Go to the top of the page 
 
  + Quote Post
Ed
post Oct 16 2009, 09:35 PM
Post #4


Outrageously Uber Ninja
*******

Group: Administrators
Posts: 2,831
Joined: 11-March 07
From: UK
Member No.: 9



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
Go to the top of the page 
 
  + Quote Post
The Seventh Hoka...
post Oct 16 2009, 10:32 PM
Post #5


Member
**

Group: Members
Posts: 90
Joined: 29-May 09
Member No.: 97,073



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:
Attached File  databasepic.jpg ( 8.54k ) Number of downloads: 109


the select list i'm trying to populate:
Attached File  db2.jpg ( 5.1k ) Number of downloads: 107


Go to the top of the page 
 
  + Quote Post
 Closed Topic Start new topic
left right
0 Members:
left right
 


Lo-Fi Version Time is now: 18th May 2013 - 10:09 PM