Jump to content

PHP help with AJAX


forumnz

Recommended Posts

Yes, this should be in this section...

 

I have a triple drop down box AJAX feature. Someone chooses an option from the 1st, which loads the second etc.

 

I have a heirarchy db type thing like:

 

PID  ID

0      1

0      2

1      3

1      4

1      5

1      6

2      7

 

The drop down box is meant to SELECT WHERE pid (parent id) = 0, to start off. Then (using above example) say user clicks value (ID) 2, number 7 loads (ID 7 with PID 2).

 

The problem is that The second dropdown box (as far as I got), always loads the items with PID 0 (like the first box).

 

This is the main code that matters. I have enclosed the 3rd section in /* */, so just ignore it.

 

<?
     header ("Expires: Sat, 26 Jul 2008 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     
     header("content-type: application/x-javascript; charset=tis-620");
     
     $data=$_GET['data'];
     $val=$_GET['val'];
     
$dbhost = "localhost";
$dbuser = "aaa";
$dbpass = "aaa";
$dbname    = "aaa";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");  

     
     if ($data=='province') { 
          echo "<select name='province' onChange=\"dochange('amper', this.value)\">\n";
          $result=mysql_db_query($dbname,"SELECT * from ffcats where pid ='0' ORDER BY name");
	 while($row = mysql_fetch_array($result))
	 {
	 $name1 = $row['name'];
	 $id1 = $row['id'];
	 $a = $id1;
               echo "<option value=\"$id1\" >$name1</option> \n" ;
          }
     } 

 else if ($data=='amper') {
          echo "<select name='amper' onChange=\"dochange('tumbon', this.value)\">\n";
          echo "<option value='0'>======== 2 ========</option>\n";
          $val = substr($val,0,2);                                 
          $result=mysql_db_query($dbname,"SELECT * FROM ffcats WHERE pid ='$a' ORDER BY name");

           while($row = mysql_fetch_array($result))
	 {
	 $name2 = $row['name'];
	 $id2 = $row['id'];
               echo "<option value=\"$id2\" >$name2</option> \n" ;
          }
     } 

 /*else if ($data=='tumbon') {
          echo "<select  name='tumbon' >\n";
          echo "<option value='0'>======== 3 ========</option>\n";
          $val2=$val;
          $val = substr($val,0,4);
          $result=mysql_db_query($dbname,"SELECT loc_code, loc_abbr, loc_name, location_name FROM location WHERE loc_code != '000000' and loc_code != '$val2' AND loc_code LIKE '$val%' AND flag_disaster IS NULL ORDER BY loc_code, loc_abbr");
          while(list($id, $name)=mysql_fetch_array($result)){
               echo "<option value=\"$id\" >$name</option> \n" ;
          }
     }*/
     echo "</select>\n";  
?>

Please help if you can,

Sam.

Link to comment
https://forums.phpfreaks.com/topic/83951-php-help-with-ajax/
Share on other sites

  • 1 year later...

forumnz did you ever get this to work for you. I have the same script and am having problems with the second list.

interesting.. but the result for TS are confuse us

 

i think the problem are the place you put your script

in my ajax (same problem).. I put 3 div (this div was the place where list will be).. hmm.. it's kinda hard to explain

<div name=text1>/*my 1st list goes here */<div>
<div name=text2>/*my 2st list goes here, the 1st list are selecter */<div>
<div name=text3>/*my 3rd list goes here, where 2nd list already selected */<div>

sry.. not much to help

you should try this example

 

 

there 3 list = A, B, C

 

A is Nation like Washington DC, California etc

B is name of City

C is name of street

 

 

Link to comment
https://forums.phpfreaks.com/topic/83951-php-help-with-ajax/#findComment-750465
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.