| | |
Cascading Dropdown list with (AJAX, PHP)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
hi,
The problem was not with AJAX or PHP code, but it was with the xml generation. I have included the modified code. I have added a root element for the XML.
This solves your problem.
The problem was not with AJAX or PHP code, but it was with the xml generation. I have included the modified code. I have added a root element for the XML.
PHP Syntax (Toggle Plain Text)
<?php // This is a very simple data provider for the cascading dropdown // example. A *real* data provider would most likely connect to // a database, use xslt and implement some level of security. Header("Content-type: text/xml"); // get query string params $filter = $_GET['filter']; //Connect to mysql server $link = @mysql_connect("localhost","root",""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = @mysql_select_db("dropdown"); if(!$db) { die("Unable to select database"); } //Create query of Faculty $qryDepartment = " SELECT dep_id, dep_name, tbl_faculty.f_id, f_name FROM tbl_department, tbl_faculty WHERE tbl_department.f_id = tbl_faculty.f_id AND f_name = '$filter' "; $resultDepartment = mysql_query($qryDepartment); // build xml content for client JavaScript $xml = "<mxml>"; while($department = mysql_fetch_array($resultDepartment)){ $fn = $department['f_name']; $di = $department['dep_id']; $xml = $xml . '<faculty name="'.$fn.'">'; $xml = $xml . '<department id="'.$di.'">'.$department["dep_name"].'</department>'; $xml = $xml . '</faculty>'; } $xml = $xml . "</mxml>"; // send xml to client echo( $xml ); ?>
This solves your problem.
Vivek Rawat
Keep solving complexities.
Keep solving complexities.
•
•
Join Date: Aug 2007
Posts: 199
Reputation:
Solved Threads: 0
Thanks for the attachment,
BUT I don't know why the data in location.sql, can not be inerted into MySQL, and also with open it with notepad, or notepad++, the data is not readable.
Can you please post me the encoding of that, I mean localtion.sql.
Thanks
BUT I don't know why the data in location.sql, can not be inerted into MySQL, and also with open it with notepad, or notepad++, the data is not readable.
Can you please post me the encoding of that, I mean localtion.sql.
Thanks
Last edited by tanha; Jul 8th, 2008 at 10:12 am.
•
•
Join Date: Aug 2007
Posts: 199
Reputation:
Solved Threads: 0
yeah.
It is all right, JUST I deleted the cookies from the browsers, and now it is working well.
I mean, if you the faculty exist in the first drop-down, and there is no department for it into the tbldepartment, it shows nothing, and then later on if you add departments for that faculty, and you select again that faculty it does not display the related departments, untill you delete the cookies from the history.
I don't know actually why AJAX do like this?
It is all right, JUST I deleted the cookies from the browsers, and now it is working well.
I mean, if you the faculty exist in the first drop-down, and there is no department for it into the tbldepartment, it shows nothing, and then later on if you add departments for that faculty, and you select again that faculty it does not display the related departments, untill you delete the cookies from the history.
I don't know actually why AJAX do like this?
Last edited by tanha; Jul 8th, 2008 at 11:33 am.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Totaling multiple sums in one array
- Next Thread: Walking Through a Multi-Demnsional PHP Array
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validation validator variable video virus web window.onbeforeunload=closeme; xml youtube






