LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2004, 07:47 AM   #1
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Rep: Reputation: 30
Select Box, PHP


Does any one know how to get the <optuon value=""> in a select box to pull from a table?
 
Old 08-03-2004, 01:34 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Im not really sure what you mean. Do you mean that you have an array of values and you want each to be an option? Just use a for or while loop to create each option tag.
 
Old 08-03-2004, 02:01 PM   #3
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
I have a HTML drop down menu. there are 10 fields each menu has about 400 options X 10 fields is 4,000 lines of code. It is really slowing down the page. I would like to have the options in a table instead of the HTML. take a look at www.oursubs.com/RT


Thanks,
-AG
 
Old 08-03-2004, 02:35 PM   #4
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
If you still wish to present the viewer with the same option of finding a menu entry to select their choice, maybe reconsider redesigning the layout of the page to have just one pull down menu, and some sort of Add button, which adds the currently selected menu item to a displayed list. It would require a little Javascript to keep an array of the chosen items, and maybe a nicely formatted area with remove buttons in case of a mistaken choice, but should still provide the same ease of selection instead of having the viewer remember and type in their codes, and then having the recieving page check for any spelling errors.
 
Old 08-03-2004, 02:41 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I'm not sure what you mean by a table. Since you don't want it in the html I assume yuo mean a database table?

You could certainly store them there but you are sill going to need to send the data to the client.

You may want to check your server's network connection. Looking at a traceroute there is a bit of a lag on the last hop - this may be causing you some of the problems.
 
Old 08-03-2004, 02:45 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
After reading Proud's post I think I see what you are getting at now. Since the select boxes are all the same you just want the user to be able to make multiple selections from the same choices. Why not use 1 select box that lets you choose multiple options?

Just replace your select tag with something like:
<select name="code" size="15" multiple>
 
Old 08-03-2004, 02:54 PM   #7
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
Cool but how do i get multipol selections to insert in to diffrent fields in the database?
 
Old 08-03-2004, 03:26 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
php has a special way of handling multiple selections. If you use:
name="code[]"

Then an array called "code" is created containing the selected items. The first six to be selected will be:
$_POST["code"][0]
$_POST["code"][1]
until
$_POST["code"][9]

If the absolute maximum is 10 then you may want to check that the user hasn't exceded that total. If there is no limit to the number of codes that can be stored then you should probably look at having a seperate link table in your database rather than having X number of code fields in each record.
 
Old 08-04-2004, 01:15 PM   #9
Chris Parker
LQ Newbie
 
Registered: Jul 2004
Location: Houston, Texas
Distribution: Debian, Gentoo, Redhat
Posts: 17

Rep: Reputation: 0
Not sure what you want

Do you just want to know how to pull values out of a table and insert them into a select list?

I am not sure what you want, but I think this might be it:

Code:
<select name="Trade_1">
<?php
$query = "SELECT trade_name FROM trade ORDER BY trade_name";
$result = mysql_query ($query) or die ($query);
while (list ($trade_name) = mysql_fetch_row ($result)) {
?>
<option value="<?php echo $trade_name ?>"><?php echo $trade_name ?></option>
<?php
}
?>
</select>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Put Values In Select Box From Database In Jsp nimishabhatia Programming 1 07-20-2005 01:16 PM
php mysql select msound Programming 9 05-21-2005 08:44 PM
for loop inside select box opioid Programming 1 03-17-2005 02:22 PM
Changing a table contents dynamically based on select box rose_bud4201 Programming 4 01-13-2005 10:48 AM
[PHP+MySQL] Rotate order in SELECT pnh73 Programming 5 12-31-2003 04:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration