Jump to content


Photo

More select boxes with db input


  • Please log in to reply
1 reply to this topic

#1 DoggerWatson

DoggerWatson
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 26 April 2005 - 09:46 AM

G'day
I love this forum ...great place for noobie like me to pick up pointers & REAL help.

If I have a list /menu how can I populate it with the results from a query.

Theres about 40 possible values so far
eg bob, bill, mary etc & growing all the time.

There must be a simpler way than adding to the list of options.

Assume the db is test
table is product
field is name

Thanks in advance
Ken

#2 bzerr

bzerr
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationCold Lake, Alberta, Canada

Posted 26 April 2005 - 03:31 PM

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?
[/span][span style=\"color:#FF8000\"]//database like this
// id     name
//--------------
// 1      Dog
// 2      Fish
// 3      Cat

[/span][span style=\"color:#0000BB\"]mysql_connect[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"localhost\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"user\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"password\"[/span][span style=\"color:#007700\"]);
[/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"test\"[/span][span style=\"color:#007700\"]);
[/span][span style=\"color:#0000BB\"]$res[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"SELECT * FROM product\"[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
echo [/span][span style=\"color:#DD0000\"]\"<select name=myselect>\"[/span][span style=\"color:#007700\"];
while([/span][span style=\"color:#0000BB\"]$row[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]mysql_fetch_assoc[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$res[/span][span style=\"color:#007700\"])) {
  echo [/span][span style=\"color:#DD0000\"]\"<option value=$row[id]>$row[name]</option>\"[/span][span style=\"color:#007700\"];
}
echo [/span][span style=\"color:#DD0000\"]\"</select>\"[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]?>[/span]
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]
Apache 1.3.33
MySQL 4.0.21
PHP 5.0.3
Linux 2.6.3




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users