php, ajax mysql drop down menu

easyrider439
easyrider439 used Ask the Experts™
on
Hey Guys, being that php is server side and javascript is browser, when the clients click a "add row" button when that new row is created how could I add a Select drop down menu created in php and mysql, I think ajax would solve this but im not sure how to write it. anybody have any tutorials or examples I can go off of? Thanks Experts!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jagadishwor DulalSenior Web Developer

Commented:
You want to work with table or some thing else?  If yes
http://www.tizag.com/ajaxTutorial/ajax-mysql-database.php
Mohamed AbowardaSenior Software Engineer

Commented:
Use AJAX to request the data from your database, PHP will handle your request and get the data from the database, use echo() to response to the AJAX request, now you can create the DOM element in javascript and fill it using the data you received from the server.

Adding drop down list and filling it using javascript:
http://chiragrdarji.wordpress.com/2007/06/06/add-items-in-drop-down-list-or-list-box-using-javascript/
Commented:
Instead of all that custom code, I prefer to work with existing libraries to handle even ajax related tasks.  Look how easy with jquery:
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

All you need to do is put in a database-driven dropdown into where your row gets added.  Then, make the ajax request (save to database using php file) when the click the menu or, whatever your condition may be.  Here's how to do database-driven dropdown menu with php and mysql:

(Code example attached.)

Ref.  http://www.phpfreaks.com/forums/index.php?topic=148900.0
<?php

//Header font drop downinclude "connect.php";   

$query="SELECT font FROM headerfont";  
$result=mysql_query($query); 

echo "<select name=\"font\">";
echo "<option value=\"None shosen\">Choose:</option>\n";

while($row = mysql_fetch_assoc($result)){   

echo "<option value=\"".trim($row["font"])."</option>\n";   

}

echo "</select>";

?>

Open in new window

Commented:
The question states:  "I think ajax would solve this but im not sure how to write it ... anybody have any tutorials or examples I can go off of?"

I gave an example of an ajax solution, just as was requested.  I think my answer answers this question.
Mohamed AbowardaSenior Software Engineer

Commented:
This question should be closed by accepting multiple solutions.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial