hamidhassas
جمعه 09 خرداد 1393, 23:44 عصر
راحت تر بگم میخوام پنج تا select داشته باشم که اطلاعات رو از دیتابیس بخونن به ترتیب یکی دسته محصولات دومی شرکت سازنده محصولات سومی نوع محصول و چهارمی قطعات اون محصول و پنجمی اصلی یا چینی بودن محصول
Select1:
Mobile
Tablet
PC
Select2:
Nokia
Samsung
LG
Select3:
5800
N97
Galexy S
Xperia
Select4:
LCD
Body
Charger
Battry
Select5:
Orginal
Remark
سورس هایی تو اینترنت پیدا کردم هر کدوم رو میخوام تغییر بده نمیتونم مثلا یکیش کد زیر اگه دوستان بتونن کمکم کنن ممنون میشم
این کد های منه مشکلم اینه که فایل findCityDay.php عمل نمیکنه یعنی وقتی به ترتیب select ها رو انتخاب میکنم هیچ محتوایی در CityDay نمایش داده نمیشه
119701
index.php
<html>
<head>
<title>Roshan's Triple Ajax dropdown code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL="findState.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req. responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(countryId,stateId) {
var strURL="findCity.php?country="+countryId+"&state="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.r esponseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCityDay(countryId,stateId) {
var strURL="findCityDay.php?country="+countryId+"&state="+stateId+"&city="+cityId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('cityday').innerHTML=req.r esponseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Country</td>
<td width="150"><select name="country" onChange="getState(this.value)">
<option value="">Select Country</option>
<option value="1">USA</option>
<option value="2">Canada</option>
</select></td>
</tr>
<tr style="">
<td>State</td>
<td ><div id="statediv"><select name="state" >
<option>Select Country First</option>
</select></div></td>
</tr>
<tr style="">
<td>City</td>
<td ><div id="citydiv"><select name="city">
<option>Select State First</option>
</select></div></td>
</tr>
<tr>
<td>cityday</td>
<td><div id="citydaydiv"><select name="cityday">
<option>Select State First</option>
</select></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
findState.php
<?php $country=intval($_GET['country']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,statename FROM state WHERE countryid='$country'";
$result=mysql_query($query);
?>
<select name="state" onchange="getCity(<?=$country?>,this.value)">
<option>Select State</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['id']?>><?php echo $row['statename']?></option>
<?php } ?>
</select>
findCity.php
<?php $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,city FROM city WHERE countryid='$countryId' AND stateid='$stateId'";
$result=mysql_query($query);
?>
<select name="city" onchange="getCityDay(<?=$stateId?>,this.value)">
<option>Select City</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['city']?></option>
<?php } ?>
</select>
findCityDay.php
<?php $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$cityId=intval($_GET['city']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,cityday FROM cityday WHERE countryid='$countryId' AND stateid='$stateId' AND city='$ctiyId'";
$result=mysql_query($query);
?>
<select name="cityday">
<option>Select CityDAY</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['cityday']?></option>
<?php } ?>
</select>
Select1:
Mobile
Tablet
PC
Select2:
Nokia
Samsung
LG
Select3:
5800
N97
Galexy S
Xperia
Select4:
LCD
Body
Charger
Battry
Select5:
Orginal
Remark
سورس هایی تو اینترنت پیدا کردم هر کدوم رو میخوام تغییر بده نمیتونم مثلا یکیش کد زیر اگه دوستان بتونن کمکم کنن ممنون میشم
این کد های منه مشکلم اینه که فایل findCityDay.php عمل نمیکنه یعنی وقتی به ترتیب select ها رو انتخاب میکنم هیچ محتوایی در CityDay نمایش داده نمیشه
119701
index.php
<html>
<head>
<title>Roshan's Triple Ajax dropdown code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL="findState.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req. responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(countryId,stateId) {
var strURL="findCity.php?country="+countryId+"&state="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.r esponseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCityDay(countryId,stateId) {
var strURL="findCityDay.php?country="+countryId+"&state="+stateId+"&city="+cityId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('cityday').innerHTML=req.r esponseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Country</td>
<td width="150"><select name="country" onChange="getState(this.value)">
<option value="">Select Country</option>
<option value="1">USA</option>
<option value="2">Canada</option>
</select></td>
</tr>
<tr style="">
<td>State</td>
<td ><div id="statediv"><select name="state" >
<option>Select Country First</option>
</select></div></td>
</tr>
<tr style="">
<td>City</td>
<td ><div id="citydiv"><select name="city">
<option>Select State First</option>
</select></div></td>
</tr>
<tr>
<td>cityday</td>
<td><div id="citydaydiv"><select name="cityday">
<option>Select State First</option>
</select></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
findState.php
<?php $country=intval($_GET['country']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,statename FROM state WHERE countryid='$country'";
$result=mysql_query($query);
?>
<select name="state" onchange="getCity(<?=$country?>,this.value)">
<option>Select State</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['id']?>><?php echo $row['statename']?></option>
<?php } ?>
</select>
findCity.php
<?php $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,city FROM city WHERE countryid='$countryId' AND stateid='$stateId'";
$result=mysql_query($query);
?>
<select name="city" onchange="getCityDay(<?=$stateId?>,this.value)">
<option>Select City</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['city']?></option>
<?php } ?>
</select>
findCityDay.php
<?php $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$cityId=intval($_GET['city']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('select');
$query="SELECT id,cityday FROM cityday WHERE countryid='$countryId' AND stateid='$stateId' AND city='$ctiyId'";
$result=mysql_query($query);
?>
<select name="cityday">
<option>Select CityDAY</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['cityday']?></option>
<?php } ?>
</select>