抓住两个价值而不是一个 [英] Grabbing Two Values Instead Of One

查看:67
本文介绍了抓住两个价值而不是一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

然而,到目前为止,我的脚本运行良好;我发现需要传递两个值。不只是一个。现在我从tblLocations传递RestID。我还需要来自同一个表的CityID。如何传递这两个值?



<?php require('   config.php'); ?> 
// 这是基于地点,城市,区域

$( document )。ready( function ()
{

$( 。Doggie)。change(函数()
{
var LocationString = ' Lid =' + $( this )。val();

$ .ajax ({
类型: POST
url: ajax_city.php
data:LocationString,
cache: false
成功: function (html){
$( .Kitty)。html(html);
}
});
});

$(' .Kitty')。live( 更改 function (){
var LocationString = ' Lid =' + $( this )。val();

$ .ajax({
type: POST
url: ajax_area.php
data:LocationString,
cache: false
成功: function (html){
$( .Pig)。html(html);
}
});

});



});
< / script>
< / head >
< body>


< div id = frame1>
< label>地点:< / label >
< select name = Doggie class = Doggie id = Doggie>
<选择选项= 选中> - 选择地点 - < / 选项 >
<?php

$ sql = mysql_query( SELECT tblLocations.RestID as Lid,tblRestaurants .RestName as name
FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
GROUP BY tblLocations.RestID,tblRestaurants.RestName
ORDER BY tblRestaurants.RestName ASC
) ;
while ($ row = mysql_fetch_array($ sql))
{
echo ' < option value ='。$ row [' Lid']。' >'。$ row [< span class =code-string>' name']。' < /选项>';
}?>
< / 选择 >
< label>城市:< / label >
< select name = Kitty class = Kitty id = < span class =code-string>
Kitty>
<选择选项= 选择> - 选择城市 - < / 选项 >
< / 选择 >
< label>面积:: < / label >
< select name = Pig class = id = Pig>
<选择选项= 选中> - 选择区域 - < / 选项 >
< / 选择 >
< / div >

< / body >
< / html >





其中一个PHP文件



 <?php  
require(' config。 PHP);

if($ _ POST [' Lid'])
{
$ Lid = $ _ POST [' Lid'];

$ sql = mysql_query( SELECT tblLocations.RestID为LID,tblAreas.AreaName为名称
FROM tblLocations INNER JOIN tblAreas ON tblLocations.AreaID = tblAreas.AreaID
WHERE tblLocations.RestID = $ Lid
GROUP BY tblLocations.RestID,tblAreas.AreaName
ORDER BY tblAreas.AreaName ASC);

echo ' <选择的选项=已选择> - 选择区域 - < / option>';
while($ row = mysql_fetch_array($ sql))
{
echo ' < option value ='。$ row [' Lid']。' >'。$ row [< span class =code-string>'
name']。' < /选项>';
}
}

?>

解决方案

document )。ready( function ()
{


。Doggie)。change(< span class =code-keyword> function ()
{
var LocationString = ' Lid =' +


this )VAL();

I have this script that works very well so far, however; its come to light that I need two values passed along. Not just one. Right Now I am passing the RestID from the tblLocations. I also need the CityID from the same table. How can I pass the two values along?

<?php require('config.php'); ?>
//This is based on Place, City, Area

$(document).ready(function()
{
	
$(".Doggie").change(function()
{
	var LocationString = 'Lid='+ $(this).val();
	
    $.ajax({
        type: "POST",
        url: "ajax_city.php",
        data: LocationString,
		cache: false,
        success: function (html) {
            $(".Kitty").html(html);
        }
    });
});

$('.Kitty').live("change",function(){
	var LocationString = 'Lid='+ $(this).val();
	
    $.ajax({
        type: "POST",
        url: "ajax_area.php",
        data: LocationString,
        cache: false,
        success: function (html) {									   
$(".Pig").html(html);
} 
});

});



});
</script>
</head>
<body>


		<div id="frame1">
  		<label>Place :</label>
  		<select name="Doggie" class="Doggie" id="Doggie">
    	<option selected="selected">--Select Place--</option>
    	<?php
		
		$sql = mysql_query("SELECT tblLocations.RestID as Lid, tblRestaurants.RestName as name
			FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
			GROUP BY tblLocations.RestID, tblRestaurants.RestName
			ORDER BY tblRestaurants.RestName ASC");
		while($row=mysql_fetch_array($sql))
		{
		echo '<option value="'.$row['Lid'].'">'.$row['name'].'</option>';
				} ?>
 		 </select>
  		<label>City :</label>
  		<select name="Kitty" class="Kitty" id="Kitty">
    	<option selected="selected">--Select City--</option>
  		</select>
  		<label>Area: :</label>
  		<select name="Pig" class="Pig" id="Pig">
    	<option selected="selected">--Select Area--</option>
  		</select>
		</div>
       
</body>
</html>



And one of the PHP files

<?php
require('config.php');

if($_POST['Lid'])
{
$Lid=$_POST['Lid'];

$sql=mysql_query("SELECT tblLocations.RestID as LID, tblAreas.AreaName as name
				FROM tblLocations INNER JOIN tblAreas ON tblLocations.AreaID = tblAreas.AreaID
				WHERE tblLocations.RestID = $Lid
				GROUP BY tblLocations.RestID, tblAreas.AreaName
				ORDER BY tblAreas.AreaName ASC");

echo '<option selected="selected">--Select Area--</option>';
while($row=mysql_fetch_array($sql))
{
echo '<option value="'.$row['Lid'].'">'.$row['name'].'</option>';
}
}

?>

解决方案

(document).ready(function() {


(".Doggie").change(function() { var LocationString = 'Lid='+


(this).val();


这篇关于抓住两个价值而不是一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆