0

Hi all,
I have taken from net chained select script.
here is all PHP and Javascript files but i dont understand one thing there.
index.php file

<?php 
  include('db.php');
  include('func.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chained Select Boxes using PHP, MySQL and jQuery</title>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
	$('#wait_1').hide();
	$('#drop_1').change(function(){
	  $('#wait_1').show();
	  $('#result_1').hide();
      $.get("func.php", {
		func: "drop_1",
		drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>
</head>

<body>
<p>
<form action="" method="post">
  
    <select name="drop_1" id="drop_1" size="4">
    
      <option value="" selected="selected" disabled="disabled">Select a Category</option>
      
      <?php getTierOne(); ?>
    
    </select> 
    
    <span id="wait_1" style="display: none;">
    <img alt="Please Wait" src="ajax-loader.gif"/>
    </span>
    <span id="result_1" style="display: none;"></span> 
  
</form>
</p>
<p>
<?php if(isset($_POST['submit'])){
	$drop = $_POST['drop_1'];
	$tier_two = $_POST['tier_two'];
	echo "You selected ";
	echo $drop." & ".$tier_two;
}
?>
<p><a href="three-tier/">View 3 Tier Select Box Example</a></p>
</body>
</html>

func.php file

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
	$result = mysql_query("SELECT DISTINCT tier_one FROM two_drops") 
	or die(mysql_error());

	  while($tier = mysql_fetch_array( $result )) 
  
		{
		   echo '<option value="'.$tier['tier_one'].'">'.$tier['tier_one'].'</option>';
		}

}

//**************************************
//     First selection results     //
//**************************************


if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}  

function drop_1($drop_var)
{  
    include_once('db.php');
	$result = mysql_query("SELECT * FROM two_drops WHERE tier_one='$drop_var'") 
	or die(mysql_error());
	
	echo '<select name="tier_two" id="tier_two" size="4">
	      <option value=" " disabled="disabled" selected="selected">Choose one</option>';

		   while($drop_2 = mysql_fetch_array( $result )) 
			{
			  echo '<option value="'.$drop_2['tier_two'].'">'.$drop_2['tier_two'].'</option>';
			}
	
	echo '</select> ';
	echo '<textarea rows="15 cols="12">dgd gdfg dgdfg</textarea>';
    echo '<input type="submit" name="submit" value="Submit" />';
}
?>

But i didnt understand what is

if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

in func.php file.
where is $_GET option. where is $_GET method used?
thanks inadvance!

2
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by azegurb
0

Thank you very much. bu i am still confused of $.get jquery method. Can you tell a little about it for what purposes it is used? what is the difference between $.ajax and $.get method. Thanks again for attention. if possible i will wait your responses

0

$.get() internally calls $.ajax() with type GET.

I am very sorry again.

if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

where is

$_GET['drop_var']

. how it can be retrieved via GET?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.