Advertisement

03.27.2008 at 12:42PM PDT, ID: 23275368
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How do you add a form field that allows users to enter a name but also has a drop down box of all unique entries for a particular database field?
Tags: PHP, HTML, JavaScript, Firefox 2.0
Heya,

I would like to add a field to a form that allows users to add a text name or pick one that already exists (based on a field in a MySQL db called 'route') using a drop-down box/menu. So the drop-down should list all unique values for the field 'route'.

Hope you understand what i mean and can show me how its done.


Cheers
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: Daniish
Solution Provided By: rowejd
Participating Experts: 1
Solution Grade: B
Views: 0
Translate:
Loading Advertisement...
03.27.2008 at 12:58PM PDT, ID: 21225193

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 01:00PM PDT, ID: 21225208

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 04:49PM PDT, ID: 21226863

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 05:21PM PDT, ID: 21227008

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 05:25PM PDT, ID: 21227022

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 05:44PM PDT, ID: 21227105

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 06:30PM PDT, ID: 21227334

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.28.2008 at 02:21AM PDT, ID: 21228898

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.28.2008 at 05:07AM PDT, ID: 21229589

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.27.2008 at 12:58PM PDT, ID: 21225193

Rank: Master

You could do your query like this:

select * from your_table GROUP BY route

Then when you fetch your rows, you can run a while loop to loop them into select fields.  Let's assume your fields are "route_id" as the primary key, and then "route" as the name of the route:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
$results = mysql_query("select * from route_table GROUP BY route");
 
if(mysql_num_rows($results) > 0){
 
    echo "<select name=\"route\">";
 
        while($row = mysql_fetch_object($results)){
   
         echo "<option value=\"$row->route_id\">$row->route</option>";
  }
  echo "</select>";
}
else
{
  echo("No values found.");
}
Open in New Window
 
03.27.2008 at 01:00PM PDT, ID: 21225208

Rank: Master

And here's an example using mysql_fetch_array() rather than fetching the object:

http://www.experts-exchange.com/Database/MySQL/Q_23047730.html
 
03.27.2008 at 04:49PM PDT, ID: 21226863
How do i combine these two:

<tr>
<td>Is this on a route? <br><input type="text" size="25" id="route" method="post" name="route"></input>
<br></td>
</tr>

and....
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<?php
$results = mysql_query("select * from locations GROUP BY route");
 
if(mysql_num_rows($results) > 0){
 
    echo "<select name=\"route\">";
 
        while($row = mysql_fetch_object($results)){
   
         echo "<option value=\"$row->id\">$row->route</option>";
  }
  echo "</select>";
}
?>
Open in New Window
 
03.27.2008 at 05:21PM PDT, ID: 21227008

Rank: Master

Well, first I dunno if you copied straight from your source, but you really can't put a method into a text input.  It should be:

<form method="POST" action="page_that_processes_your_form.php">
<input type="text" name="route" size="25" id="route" />
<input type="submit" name="submit" value="Submit" />

Setting that aside, though.  If I understand correctly you want to allow them to (a) Choose a route that already exists in your database or (b) Insert a new route that you don't have listed.  To do this, I would write your form this way:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
 
<form method="POST" action="page_that_processes_your_form.php">
Please select which route it is on:<br />
 
<?php
$results = mysql_query("select * from locations GROUP BY route");
 
if(mysql_num_rows($results) > 0){
 
    echo "<select name=\"route\">";
 
        while($row = mysql_fetch_object($results)){
   
         echo "<option value=\"$row->id\">$row->route</option>";
  }
  echo "</select>";
}
?>
<br /><br />
If the route is not listed in the drop down box, please type it here:<br />
<input type="text" name="route" size="25" id="route" />
<br /><br />
<input type="submit" name="submit" value="Submit" />
</form>
Open in New Window
Accepted Solution
 
03.27.2008 at 05:25PM PDT, ID: 21227022

Rank: Master

Now the other part of this is how you process the form entry.  I'm not sure if you want to enter the route that they typed into your database, or if you want to do something else with that value -- but that's probably a separate question.  You could go about it 2 different ways:

1) Modify the code I gave you above and give them different NAME values in the HTML.  Then when the form is processed you can test to see which value is set and process results according to which one they chose.

2) Take their entry despite which they chose, and test it against your database to see if it matches a database entry.  If not, you would add it to the database.  If so - you'd move on with your code and use the value in whatever way you wish.
 
03.27.2008 at 05:44PM PDT, ID: 21227105
Thanks rowejd...

I would like to give users a list of routes that already exist so that they can choose one if it fits where they are, but if it doesn't i also want them to be able to add a new route name....pref all from one input box on the form.

I already have a script which will populate my database with whatever they enter into the route field on the form (please see this in the code snippet below). I have also attached the input form that i'm using for your reference.

I think i'm aiming for option 1) in your last post.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
<?php
require('includes/dbinfo.php'); 
 
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("web25-daniish", $db);
 
$sql="INSERT INTO locations (name, title, date, description, lat, lng, link, icon, route) 
VALUES
('$_POST[name]','$_POST[title]','$_POST[date]','$_POST[description]','$_POST[lat]','$_POST[lng]','$_POST[link]','$_POST[icon]','$_POST[route]')";
 
if (!mysql_query($sql,$db))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added ";
 
echo "<a href='http://www.globexposure.net/members/my_demos/input_form/input_form.html'>Add another POI</a>";
 
mysql_close($db)
?>
Open in New Window
 
This is the input-form.html
 
 
03.27.2008 at 06:30PM PDT, ID: 21227334

Rank: Master

A question for you...do you have a separate ROUTES table?  Or is the list of routes pulled from & populated from the same "locations" table?  I mean if you have 1,000 POI's and 200 different routes...that'd be cumbersome to look through eh?

Or is the list of routes one that you control and add to / delete from as you see popular routes?  If that's the case then you wouldn't want to add a route to your separate routes table every time a user adds a POI with a different route -- you'd just populate the locations table with the route name and let that be that.

This makes a big difference in how you go about this.
 
03.28.2008 at 02:21AM PDT, ID: 21228898
The route field is in the locations table and only has 1 value atm, but its an interesting point you have raised.

Perhaps instead of listing all the route values it should just give the user the 'last' (date wise) route used... (or allow them to add a new one).....yep that sounds like a much better solution!

 
03.28.2008 at 05:07AM PDT, ID: 21229589

Rank: Master

I would tend to agree.  Either that or you could make a simple list that's not even tied to a database -- of the most common routes for them to choose from.  If you had a separate ROUTES table, you'd have to deal with the relationship between the locations table and the routes table and it gets more complex.  If you're wanting to keep it simple - I'd just go with a list of common routes or the way you suggested if you know it would suit your application better.

Good luck!
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628