| | |
PHP mysql drop down populates another drop down
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2007
Posts: 2
Reputation:
Solved Threads: 0
Hi
I am tring to populate a drop down by selecting another drop down.
The first drop dwon populates from eventdata table and i want the second drop down to populate from a race table. I have tried to find the row which contains the same event id as the first drop down box and then display the team id which has the same event id.
NOTE event id and race id will have the same data in them, bad naming on my part
I am tring to populate a drop down by selecting another drop down.
The first drop dwon populates from eventdata table and i want the second drop down to populate from a race table. I have tried to find the row which contains the same event id as the first drop down box and then display the team id which has the same event id.
NOTE event id and race id will have the same data in them, bad naming on my part
PHP Syntax (Toggle Plain Text)
<?php include 'config.php'; include 'opendb.php'; $sql="SELECT event_Name FROM eventdata"; $result=mysql_query($sql); $optionsevent=""; while ($row=mysql_fetch_array($result)) { $event_Name=$row["event_Name"]; $event_Name=$row["event_Name"]; $optionsevent.="<OPTION VALUE=\"$event_Name\">".$event_Name; } function Generate(){ $sql="SELECT team_ID FROM race WHERE race_Name=$optionsevent"; $result=mysql_query($sql); $optionsid=""; while ($row=mysql_fetch_array($result)) { $team_ID=$row["team_ID"]; $team_ID=$row["team_ID"]; $optionsid.="<OPTION VALUE=\"$team_ID\">".$team_ID; } } ?> <html> <head> <title>Rally Database - Results Entry Form</title><style type="text/css"> <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 24px; } body { background-color: #CCCCCC; } --> </style><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <body> <div align="center"> <p><strong><span class="style1">Results Entry Form</span></strong></p> <p align="left">Please enter select the Race ID and then the Team ID. </p> </div> <form method="post" action="enterresultsinsert.php"> <label></label> <p> <label></label> <label></label> <label>Race ID <select name="raceid"> <OPTION VALUE=0 onChange="Generate();" >Choose <?=$optionsevent?> </select> </select> </label> <label>Team ID <select name="teamid"> <OPTION VALUE=0>Choose <?=$optionsid?> </select> </select> </label> </p> <p> <label>Stage 1 Time <input name="stage1" type="text"> </label> </p> <p> <label>Stage 2 Time <input name="stage2" type="text"> </label> </p> <p> <label>Stage 3 Time <input name="stage3" type="text"> </label> </p> <label>Stage 4 Time <input name="stage4" type="text"> </label> <p> <label>Stage 5 Time <input name="stage5" type="text"> </label> </p> <p> <label>Stage 6 Time <input name="stage6" type="text"> </label> </p> <p> <label>Stage 7 Time <input name="stage7" type="text"> </label> </p> <p> <label>Stage 8 Time <input name="stage8" type="text"> </label> </p> <p> <label>Total Time <input name="total" type="text"> </label> </p> <p> <label></label> <label></label><label> <input type="submit" name="Submit" value="Add Results"> </label> </p> </form> </body> </html>
•
•
Join Date: Jan 2006
Posts: 3
Reputation:
Solved Threads: 0
Do you want a server-side refresh of the second SELECT object, or a "<BODY onload=..." javascript that contains all the nested option lists?
The first solution could use AJAX to rewrite the options, triggered by the onchange event of the first SELECT object.
For the second solution, google the EasySelect javascript off the web, then use php to hit your database and write the arrays that Easyselect uses to populate its SELECT options.
The first solution could use AJAX to rewrite the options, triggered by the onchange event of the first SELECT object.
For the second solution, google the EasySelect javascript off the web, then use php to hit your database and write the arrays that Easyselect uses to populate its SELECT options.
again i would say
is there any solution that does not posts the page back to the sever and does not make your page weight like a ton
except AJAX.......
well i really would like to know about it
and anyway sorry for using the word "ONLY" after rethinking it is not so professional
word ............................
is there any solution that does not posts the page back to the sever and does not make your page weight like a ton
except AJAX.......
well i really would like to know about it
and anyway sorry for using the word "ONLY" after rethinking it is not so professional
word ............................
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
- th3 php wr3nch -
There is at least one other solution to the problem: you save all your data in javascript tables and use onchange() event on one drop down to populate another from respective javascript table. The javascript can be put in an external file (if the information doesn't change to often, so it can be cached by the browsers and load faster) or can be generated on the fly from php, every time the script loads, if it updates often.
I've done this for a site few years ago, when ajax wasn't an option. And it works like a charm
I've done this for a site few years ago, when ajax wasn't an option. And it works like a charm
![]() |
Similar Threads
- PHP and MySQL Web Development (PHP)
- Genuis PHP/Mysql programmers and Awesome Designers! (Web Development Job Offers)
- master database with php mysql (Legacy and Other Languages)
- Flash Poll System using php/mysql for free (Graphics and Multimedia)
- PHP/MySQL programmer available (Post your Resume)
- Integrating Apache with PHP and MySQL (Linux Servers and Apache)
- Using PHP, MySQL and Apache Server (PHP)
Other Threads in the PHP Forum
- Previous Thread: php+javascript
- Next Thread: I purchased VBulletin...but
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





