首先我从MYSQl获取数组,当Ajax显示更改值结果时我有选择输入
echo "<select onchange='showUser(this.value)'> <option>Select Unit</option>";
$query="select * from item_units WHERE item_id='".$item_id."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$item_unit =$row['item_unit'];
$query4 = "SELECT unit_name FROM unit WHERE unit_id='".$item_unit."'";
$rest4 = mysql_query($query4);
if(isset($rest4))
$unit_name4 = mysql_result($rest4, 0);
echo "<option value='$item_unit'>$unit_name4</option>";
}
echo"</select><br /> ";
然后我从mysql中获取$ item_id
$query="select * from items WHERE item_id='".$item_id2."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$item_id=$row['item_id'];}
然后使用
echo"<script>
function showUser(str) {
if (str == '') {
document.getElementById('txtHint').innerHTML = '';
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('txtHint').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','myesso.php?id=$item_id&q='+str,true);
xmlhttp.send();
}
} “;
但ID = $ item_id的值没有值因为OF值超过每条记录的值
我如何解决它我可以将它作为阵列发送吗?
Myesso.php
Myesso.php
<?php
session_start();
include "config.php";
$q = intval($_GET['q']);
$gid = $_REQUEST['id'];
$moha = $_SESSION['logid'];
$query="select * from login WHERE login_id='".$moha."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$type =$row['type'];
$permission =$row['permission'];
}
if($type==1){
$query="select * from client WHERE login_id='".$moha."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$level_id =$row['level_id'];
$area_id =$row['area_id'];
}
}elseif($type==2){
$query="select * from department WHERE login_id='".$moha."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$level_id =$row['level_id'];
$area_id =$row['area_id'];
}
}elseif($type==3){
$query="select * from clerk WHERE login_id='".$moha."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$level_id =$row['level_id'];
$area_id =$row['area_id'];
}
}
$sql="SELECT * FROM item_price WHERE unit_id='".$q."' && level_id = '".$level_id."' && area_id ='".$area_id."' && item_id='".$gid."' ";
$result = mysql_query($sql);
while($rows = mysql_fetch_array($result)) {
$price = $rows['price'];
echo"<span class='item-price-special'>$price</span>";
}
mysql_close();
?>
答案 0 :(得分:2)
试试这个替换所有的mywishlist.php
<?php
$query2="select * from wishlist WHERE client_id='".$client_id."'";
$res2=mysql_query($query2);
if(!$res2){die(mysql_error());}
while($rows=mysql_fetch_array($res2)){
$item_id2 =$rows['item_id'];
$query="select * from items WHERE item_id='".$item_id2."'";
$res = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$shop_id =$row['shop_id'];
$cat_id =$row['cat_id'];
$sub_id =$row['sub_id'];
$brand_id=$row['brand_id'];
$item_name=$row['item_name'];
$item_id=$row['item_id'];
$item_img=$row['item_img'];
$item_code=$row['item_code'];
$item_over=$row['item_over'];
$item_des=$row['item_des'];
echo "<script>
function showUser(str) {
if (str == '') {
document.getElementById('txtHint').innerHTML = '';
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('txtHint').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','myesso.php?id=$item_id&q='+str,true);
xmlhttp.send();
}
}
</script> ";
$query = "SELECT cat_name FROM cat WHERE cat_id ='".$row['cat_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$cat_name = mysql_result($rest, 0);
$query = "SELECT brand_name FROM brand WHERE brand_id ='".$row['brand_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$brand_name = mysql_result($rest, 0);
$query = "SELECT sub_name FROM subcat WHERE sub_id ='".$row['sub_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$sub_name = mysql_result($rest, 0);
}
echo "
<tr>
<td style='width:500px' class='item-name-col'>
<figure>
<a href='product.php?id=$item_id'><img src='products/$item_img'></a>
</figure>
<header class='item-name'><a href='product.php?id=$item_id'>$cat_name , $sub_name , $brand_name , $item_name</a></header>
<ul>
<li>Item Code: $item_code</li>
</ul>
</td>
<td class='item-code'>
<div id='category-list-1' class='collapse in'>
<div class='panel-body'>
<ul class='category-filter-list jscrollpane'>";
$query="select * from item_colors WHERE item_id='".$item_id."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$color_id =$row['color_id'];
$query = "SELECT color_code FROM color WHERE color_id ='".$row['color_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$color_code = mysql_result($rest, 0);
echo "<li><a href='#'><label class='checkbox-inline'><input type='checkbox' id='".$color_id."' name='colors[]' value='".$color_id."'> <span style='padding:10px;width:10px;background:$color_code'></span></label></a></li><br />";
}
echo "</ul>
</div><!-- End .panel-body -->
</div><!-- #collapse -->";
echo "
</td>
<td class='item-price-col'> <select style='width:150px' class='form-control' onchange='showUser(this.value)'>
<option>Select Unit</option>";
$query="select * from item_units WHERE item_id='".$item_id."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$item_unit =$row['item_unit'];
$query4 = "SELECT unit_name FROM unit WHERE unit_id='".$item_unit."'";
$rest4 = mysql_query($query4);
if(isset($rest4))
$unit_name4 = mysql_result($rest4, 0);
echo "<option value='$item_unit'>$unit_name4</option>";
}
echo"</select><br />
<div id='txtHint'></div>
</td>
答案 1 :(得分:-2)
Mywishlist.php
<?php
$query2="select * from wishlist WHERE client_id='".$client_id."'";
$res2 = mysql_query($query2);
if(!$res2) { die(mysql_error()); }
while($rows = mysql_fetch_array($res2)) {
$item_id2 =$rows['item_id'];
$query = "select * from items WHERE item_id='".$item_id2."'";
$res = mysql_query($query);
if(!$res) { die(mysql_error()); }
while($row = mysql_fetch_array($res)) {
$shop_id =$row['shop_id'];
$cat_id =$row['cat_id'];
$sub_id =$row['sub_id'];
$brand_id=$row['brand_id'];
$item_name=$row['item_name'];
$item_id=$row['item_id'];
$item_img=$row['item_img'];
$item_code=$row['item_code'];
$item_over=$row['item_over'];
$item_des=$row['item_des'];
echo "<script>
function showUser(str) {
if (str == '') {
document.getElementById('txtHint').innerHTML = '';
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('txtHint').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','myesso.php?id=$item_id&q='+str,true);
xmlhttp.send();
}
}
</script> ";
$query = "SELECT cat_name FROM cat WHERE cat_id ='".$row['cat_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$cat_name = mysql_result($rest, 0);
$query = "SELECT brand_name FROM brand WHERE brand_id ='".$row['brand_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$brand_name = mysql_result($rest, 0);
$query = "SELECT sub_name FROM subcat WHERE sub_id ='".$row['sub_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$sub_name = mysql_result($rest, 0);
}
echo "
<tr>
<td style='width:500px' class='item-name-col'>
<figure>
<a href='product.php?id=$item_id'><img src='products/$item_img'></a>
</figure>
<header class='item-name'><a href='product.php?id=$item_id'>$cat_name , $sub_name , $brand_name , $item_name</a></header>
<ul>
<li>Item Code: $item_code</li>
</ul>
</td>
<td class='item-code'>
<div id='category-list-1' class='collapse in'>
<div class='panel-body'>
<ul class='category-filter-list jscrollpane'>";
$query="select * from item_colors WHERE item_id='".$item_id."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$color_id =$row['color_id'];
$query = "SELECT color_code FROM color WHERE color_id ='".$row['color_id']."'";
$rest = mysql_query($query);
if(isset($rest))
$color_code = mysql_result($rest, 0);
echo "<li><a href='#'><label class='checkbox-inline'><input type='checkbox' id='".$color_id."' name='colors[]' value='".$color_id."'> <span style='padding:10px;width:10px;background:$color_code'></span></label></a></li><br />";
}
echo "</ul>
</div><!-- End .panel-body -->
</div><!-- #collapse -->";
echo "
</td>
<td class='item-price-col'> <select style='width:150px' class='form-control' onchange='showUser(this.value)'>
<option>Select Unit</option>";
$query="select * from item_units WHERE item_id='".$item_id."'";
$res=mysql_query($query);
if(!$res){die(mysql_error());}
while($row=mysql_fetch_array($res)){
$item_unit =$row['item_unit'];
$query4 = "SELECT unit_name FROM unit WHERE unit_id='".$item_unit."'";
$rest4 = mysql_query($query4);
if(isset($rest4))
$unit_name4 = mysql_result($rest4, 0);
echo "<option value='$item_unit'>$unit_name4</option>";
}
echo"</select><br />
<div id='txtHint'></div>
</td>