Cascading Dropdown list with (AJAX, PHP)

Thread Solved

Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
1
  #11
Jul 8th, 2008
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.


  1. <?php
  2.  
  3. // This is a very simple data provider for the cascading dropdown
  4. // example. A *real* data provider would most likely connect to
  5. // a database, use xslt and implement some level of security.
  6.  
  7. Header("Content-type: text/xml");
  8. // get query string params
  9. $filter = $_GET['filter'];
  10.  
  11. //Connect to mysql server
  12. $link = @mysql_connect("localhost","root","");
  13. if(!$link) {
  14. die('Failed to connect to server: ' . mysql_error());
  15. }
  16. //Select database
  17. $db = @mysql_select_db("dropdown");
  18. if(!$db) {
  19. die("Unable to select database");
  20. }
  21. //Create query of Faculty
  22. $qryDepartment = "
  23. SELECT dep_id, dep_name, tbl_faculty.f_id, f_name
  24. FROM tbl_department, tbl_faculty
  25. WHERE tbl_department.f_id = tbl_faculty.f_id
  26. AND f_name = '$filter'
  27. ";
  28. $resultDepartment = mysql_query($qryDepartment);
  29.  
  30. // build xml content for client JavaScript
  31.  
  32. $xml = "<mxml>";
  33. while($department = mysql_fetch_array($resultDepartment)){
  34. $fn = $department['f_name'];
  35. $di = $department['dep_id'];
  36. $xml = $xml . '<faculty name="'.$fn.'">';
  37. $xml = $xml . '<department id="'.$di.'">'.$department["dep_name"].'</department>';
  38. $xml = $xml . '</faculty>';
  39. }
  40. $xml = $xml . "</mxml>";
  41. // send xml to client
  42. echo( $xml );
  43. ?>


This solves your problem.
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #12
Jul 8th, 2008
Thanks vicky_rawat, for the reply,
BUT it is still not working, I don't know what to do?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #13
Jul 8th, 2008
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
Originally Posted by Shanti Chepuru View Post
Check these attachments..
These are very usefull for you..

The dropdown works on both php and ajax..
Check out..
Thank
Shanti
Last edited by tanha; Jul 8th, 2008 at 10:12 am.
Attached Thumbnails
untitled.JPG  
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #14
Jul 8th, 2008
Originally Posted by tanha View Post
Thanks vicky_rawat, for the reply,
BUT it is still not working, I don't know what to do?
I tried vicky_rawat's code and it works perfectly fine..
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #15
Jul 8th, 2008
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?
Last edited by tanha; Jul 8th, 2008 at 11:33 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #16
Jul 9th, 2008
You just copy and paste the content which is in notepad into your mysql query...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #17
Jul 9th, 2008
When I copy and paste the contents in mysql query, then the data inserted, but not readable.
WHY like this? WHAT I should I do ?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #18
Jul 9th, 2008
Tanha...
Tel me what mysql version you are using...
Is it phpmyadmin or not...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #19
Jul 9th, 2008
These what i attatched are finely working...Check out once again...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Cascading Dropdown list with (AJAX, PHP)

 
0
  #20
Jul 9th, 2008
I am using:
MySQL 5.0.51b
phpMyAdmin 2.11.7

and I used the the import, and also the copy and paste in phpmyadmin, but still the inserted data is not readable?

I checked it many times, and I tried opening the file, with notepad, notepad++, and dream viewer, not readable there.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC