943,987 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 24284
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 8th, 2008
1

Re: Cascading Dropdown list with (AJAX, PHP)

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.


PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Jul 8th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

Thanks vicky_rawat, for the reply,
BUT it is still not working, I don't know what to do?
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Jul 8th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

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
Check these attachments..
These are very usefull for you..

The dropdown works on both php and ajax..
Check out..
Thank
Shanti
Attached Thumbnails
Click image for larger version

Name:	untitled.JPG
Views:	53
Size:	111.7 KB
ID:	6558  
Last edited by tanha; Jul 8th, 2008 at 10:12 am.
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Jul 8th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

Click to Expand / Collapse  Quote originally posted by tanha ...
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..
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 8th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

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.
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Jul 9th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

You just copy and paste the content which is in notepad into your mysql query...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 9th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

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 ?
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Jul 9th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

Tanha...
Tel me what mysql version you are using...
Is it phpmyadmin or not...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 9th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

These what i attatched are finely working...Check out once again...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 9th, 2008
0

Re: Cascading Dropdown list with (AJAX, PHP)

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.
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: values to database
Next Thread in PHP Forum Timeline: Download Multiple Files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC