|
|
|
ส่งค่า ajax ProductID ไปอีก files 1 เพื่อ ส่งค่ามา แสดง โดยส่งแบบ GET เพื่อ WHERE ค่าออกมา ไปไม่เป็น งง ช่วยที่ |
|
|
|
|
|
|
|
Main (PHP)
<?php
session_start();
ob_start();
require('include/db_connect.php');
require('include/function.php');
if((isset($_SESSION['lname'])));
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE; ?></title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/textcss.css" type="text/css" rel="stylesheet" >
<link href="css/styleinput.css" type="text/css" rel="stylesheet" >
<link href="css/stylelink.css" type="text/css" rel="stylesheet">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<link rel="stylesheet" type="text/css"
href="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.css" />
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js"> </script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.css"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.min.css"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js"></script>
<body>
<?php
if($_SESSION['lL'] == 1)
{
$Se="SELECT distinct
product_main.ProAuto,
product_main.ProductID,
product_main.DeptID,
product_main.ProductNameLao,
product_main.TypeID,
product_main.Size,
product_main.Price,
product_main.Result,
product_main.QTYMain,
product_main.DateMain,
product_main.Remark,
product_main.AdminID,
currency.CurrencyID,
currency.CurrencyName,
brand.BrandID,
brand.BrandName,
asset_province.APID,
asset_province.AssetProvince_Name,
tbphoto.PhotoID
FROM stock_supplies.product_main
LEFT JOIN stock_supplies.currency ON currency.CurrencyID = product_main.CurrencyID
LEFT JOIN stock_supplies.brand ON brand.BrandID = product_main.BrandID
LEFT JOIN stock_supplies.asset_province ON asset_province.APID = product_main.APID
LEFT JOIN stock_supplies.tbphoto ON tbphoto.PhotoID = product_main.PhotoID";
} else {
$Se="SELECT distinct
product_main.ProAuto,
product_main.ProductID,
product_main.DeptID,
product_main.ProductNameLao,
product_main.TypeID,
product_main.Size,
product_main.Price,
product_main.Result,
product_main.QTYMain,
product_main.DateMain,
product_main.Remark,
product_main.AdminID,
currency.CurrencyID,
currency.CurrencyName,
brand.BrandID,
brand.BrandName,
asset_province.APID,
asset_province.AssetProvince_Name,
tbphoto.PhotoID
FROM stock_supplies.product_main
LEFT JOIN stock_supplies.currency ON currency.CurrencyID = product_main.CurrencyID
LEFT JOIN stock_supplies.brand ON brand.BrandID = product_main.BrandID
LEFT JOIN stock_supplies.asset_province ON asset_province.APID = product_main.APID
LEFT JOIN stock_supplies.tbphoto ON tbphoto.PhotoID = product_main.PhotoID
WHERE product_main.DeptID ='".$_SESSION['lDeptID']."'
";
}
$SQL=mysql_query($Se);
?>
<form action="" name="frmMain" id="frmMain">
<table width="96%" border="1" cellspacing="0" cellpadding="0" align="center" class="table-responsive">
<tr>
<td colspan="16"> TEST</td>
</tr>
<tr>
<td> No:</td>
<td> ProductID</td>
<td> Photo</td>
<td> Name </td>
<td> TypeID</td>
<td> Size</td>
<td> Price</td>
<td> BrandID</td>
<td> QTYMain</td>
<td> Monney</td>
<td> CurrencyID</td>
<td> AssetProvince_Name</td>
<td> DateMain</td>
<td> Remark</td>
<td> Insert Detail</td>
<td> Show Detail</td>
</tr>
<?php
$i=1;
while($row=mysql_fetch_assoc($SQL))
{
$K=number_format($row["Result"],0);
$A=$row["ProAuto"];
$P=$row["ProductID"];
$N=$row["QTYMain"];
?>
<tr>
<td> <input type="text" name="No<?php echo $i;?>" id="No" value="<?php echo $row["ProAuto"];?>"></td>
<td> <input type="text" name="ProductIDs<?php echo $i;?>" id="ProductIDs" value="<?php echo $row["ProductID"];?>"></td>
<td align="center"><img src="Photo/<?php echo $row['PhotoID'];?>" width="100" height="100" /></td>
<td> <input type="text" name="ProductNameLao<?php echo $i;?>" id="" value="<?php echo $row["ProductNameLao"];?>"></td>
<td> <input type="text" name="TypeID<?php echo $i;?>" id="TypeID" value="<?php echo $row["TypeID"];?>"></td>
<td> <input type="text" name="Size<?php echo $i;?>" id="Size" value="<?php echo $row["Size"];?>"></td>
<td> <input type="text" name="Price<?php echo $i;?>" id="Price" value="<?php echo $row["Price"];?>"></td>
<td> <input type="text" name="BrandName<?php echo $i;?>" id="BrandName" value="<?php echo $row["BrandName"];?>"></td>
<td> <input type="text" name="QTYMain<?php echo $i;?>" id="QTYMain" value="<?php echo $row["QTYMain"];?>"></td>
<td> <input type="text" name="Result<?php echo $i;?>" id="Result" value="<?php echo $row["Result"];?>"></td>
<td> <input type="text" name="CurrencyName<?php echo $i;?>" id="CurrencyName" value="<?php echo $row["CurrencyName"];?>"></td>
<td> <input type="text" name="AssetProvince_Name<?php echo $i;?>" id="" value="<?php echo $row["AssetProvince_Name"];?>"></td>
<td> <input type="text" name="DateMain<?php echo $i;?>" id="DateMain" value="<?php echo $row["DateMain"];?>"></td>
<td> <input type="text" name="Remark<?php echo $i;?>" id="Remark" value="<?php echo $row["Remark"];?>"></td>
<td align="center"><?php echo "<a href='frminsert_details.php?ProAuto=".$A."&ProductID=".$P."&n=".$N."'>
<img src='img/note_add.png' width='22' height='22' /></a>"; ?></td>
<td align="center"><input type="text" name="ProductID<?php echo $i;?>" id="ProductID" value="<?php echo $row["ProductID"]; ?>">
<script>
function getDataFromDb()
{
$.ajax({
url: "data.php" ,
type: "POST",
data: {ProductID: $("#ProductID<?php echo $i;?>").val()}
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj != '')
{
//$("#myTable tbody tr:not(:first-child)").remove();
$("#myBody").empty();
$.each(obj, function(key, val) {
var tr = "<tr>";
tr = tr + "<td>" + val["ProductID"] + "</td>";
tr = tr + "<td>" + val["ProductIDList"] + "</td>";
tr = tr + "<td>" + val["AssetDeptName"] + "</td>";
tr = tr + "<td>" + val["location"] + "</td>";
tr = tr + "<td>" + val["QTY"] + "</td>";
tr = tr + "<td>" + val["GroupName"] + "</td>";
tr = tr + "<td>" + val["DateCreate"] + "</td>";
tr = tr + "<td>" + val["DateEX"] + "</td>";
tr = tr + "<td>" + val["UseName"] + "</td>";
tr = tr + "<td>" + val["Remark"] + "</td>";
tr = tr + "</tr>";
$('#myTable > tbody:last').append(tr);
});
}
});
}
setInterval(getDataFromDb,1000); // 1000 = 1 second
</script>
<center>
<h1>My Web</h1>
<table width="600" border="1" id="myTable">
<!-- head table -->
<thead>
<tr>
<td width="91"> <div align="center">ProductID </div></td>
<td width="98"> <div align="center">ProductIDList </div></td>
<td width="198"> <div align="center">AssetDeptName </div></td>
<td width="97"> <div align="center">location </div></td>
<td width="59"> <div align="center">QTY </div></td>
<td width="71"> <div align="center">GroupName </div></td>
<td width="198"> <div align="center">DateCreate </div></td>
<td width="97"> <div align="center">DateEX </div></td>
<td width="59"> <div align="center">UseName </div></td>
<td width="71"> <div align="center">Remark </div></td>
</tr>
</thead>
<!-- body dynamic rows -->
<tbody id="myBody"></tbody>
</table>
<center>
</td>
</tr>
<?php } ?>
</table>
</div>
</form>
</body>
</html>
<?php } ?>
<?php
ob_end_flush();
mysql_close($d1,$db1,$c1);
mysql_close($d2,$db2,$c1);
exit();
?>
data (PHP)
<?php
echo $_GET["ProductID"];
require('include/db_connect.php');
$strSQL = "SELECT product_list.Auto,
product_list.ProductID,
product_list.ProductIDList,
asset_dept.AssetDeptName,
asset_dept.AssetDeptID,
product_list.location,
product_list.QTY,
group_asset.GroupName,
group_asset.GroupID,
product_list.DateCreate,
product_list.DateEX,
using.UseID,
using.UseName,
product_list.Remark,
product_list.AdminID,
product_list.DeptID
FROM stock_supplies.product_list
LEFT JOIN stock_supplies.asset_dept ON asset_dept.AssetDeptID = product_list.AssetDeptID
LEFT JOIN stock_supplies.group_asset ON group_asset.GroupID = product_list.GroupID
LEFT JOIN stock_supplies.using ON using.UseID = product_list.UseID
WHERE product_list.ProductID ='".$_GET["ProductID"]."'
ORDER By product_list.ProductID ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
งงและไม่เข้าใจเป็นเอามาก
แต่ถ้า Loop ธรรมดา <a href ส่งแบบ Get ไปเรียก show data นั้นง่ายทำเป็น แต่ อยาก ส่งเป็น Ajax > ไม่ทราบ ว่านะแนะนำ เขียนแบบไหน จึ่งจะถูกต้อง
Mysql Follow Company LoL
Tag : PHP, JavaScript, Ajax, jQuery, Google Chrome, XAMPP
|
ประวัติการแก้ไข 2017-11-28 10:11:31
|
|
|
|
|
Date :
2017-11-28 10:02:40 |
By :
Hararock |
View :
563 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
ob_start();
require('include/db_connect.php');
require('include/function.php');
if((isset($_SESSION['lname'])));
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE; ?></title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/textcss.css" type="text/css" rel="stylesheet" >
<link href="css/styleinput.css" type="text/css" rel="stylesheet" >
<link href="css/stylelink.css" type="text/css" rel="stylesheet">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<link rel="stylesheet" type="text/css"
href="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.css" />
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js"> </script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
<body>
<?php
if($_SESSION['lL'] == 1)
{
$Se="SELECT distinct
product_main.ProAuto,
product_main.ProductID,
product_main.DeptID,
product_main.ProductNameLao,
product_main.TypeID,
product_main.Size,
product_main.Price,
product_main.Result,
product_main.QTYMain,
product_main.DateMain,
product_main.Remark,
product_main.AdminID,
currency.CurrencyID,
currency.CurrencyName,
brand.BrandID,
brand.BrandName,
asset_province.APID,
asset_province.AssetProvince_Name,
tbphoto.PhotoID
FROM stock_supplies.product_main
LEFT JOIN stock_supplies.currency ON currency.CurrencyID = product_main.CurrencyID
LEFT JOIN stock_supplies.brand ON brand.BrandID = product_main.BrandID
LEFT JOIN stock_supplies.asset_province ON asset_province.APID = product_main.APID
LEFT JOIN stock_supplies.tbphoto ON tbphoto.PhotoID = product_main.PhotoID";
} else {
$Se="SELECT distinct
product_main.ProAuto,
product_main.ProductID,
product_main.DeptID,
product_main.ProductNameLao,
product_main.TypeID,
product_main.Size,
product_main.Price,
product_main.Result,
product_main.QTYMain,
product_main.DateMain,
product_main.Remark,
product_main.AdminID,
currency.CurrencyID,
currency.CurrencyName,
brand.BrandID,
brand.BrandName,
asset_province.APID,
asset_province.AssetProvince_Name,
tbphoto.PhotoID
FROM stock_supplies.product_main
LEFT JOIN stock_supplies.currency ON currency.CurrencyID = product_main.CurrencyID
LEFT JOIN stock_supplies.brand ON brand.BrandID = product_main.BrandID
LEFT JOIN stock_supplies.asset_province ON asset_province.APID = product_main.APID
LEFT JOIN stock_supplies.tbphoto ON tbphoto.PhotoID = product_main.PhotoID
WHERE product_main.DeptID ='".$_SESSION['lDeptID']."'
";
}
$SQL=mysql_query($Se);
?>
<form action="" name="frmMain" id="frmMain">
<table width="96%" border="1" cellspacing="0" cellpadding="0" align="center" class="table-responsive">
<tr>
<td colspan="16"> TEST</td>
</tr>
<tr>
<td> No:</td>
<td> ProductID</td>
<td> Photo</td>
<td> Name </td>
<td> TypeID</td>
<td> Size</td>
<td> Price</td>
<td> BrandID</td>
<td> QTYMain</td>
<td> Monney</td>
<td> CurrencyID</td>
<td> AssetProvince_Name</td>
<td> DateMain</td>
<td> Remark</td>
<td> Insert Detail</td>
<td> Show Detail</td>
</tr>
<?php
$i=0;
while($row=mysql_fetch_assoc($SQL))
{
$K=number_format($row["Result"],0);
$A=$row["ProAuto"];
$P=$row["ProductID"];
$N=$row["QTYMain"];
++$i;
?>
<tr>
<td> <input type="hidden" name="h" id="h" value="<?php echo $row["ProAuto"];?>"><?php echo $i;?></td>
<td> <input type="text" name="ProductID<?php echo $i;?>" id="ProductID" value="<?php echo $row["ProductID"];?>"></td>
<td align="center"><img src="Photo/<?php echo $row['PhotoID'];?>" width="100" height="100" /></td>
<td> <?php echo $row["ProductNameLao"];?></td>
<td> <?php echo $row["TypeID"];?></td>
<td> <?php echo $row["Size"];?></td>
<td> <?php echo $row["Price"];?></td>
<td> <?php echo $row["BrandName"];?></td>
<td> <?php echo $row["QTYMain"];?></td>
<td> <?php echo $row["Result"];?></td>
<td> <?php echo $row["CurrencyName"];?></td>
<td> <?php echo $row["AssetProvince_Name"];?></td>
<td> <?php echo $row["DateMain"];?></td>
<td> <?php echo $row["Remark"];?></td>
<td align="center"><?php echo "<a href='frminsert_details.php?ProAuto=".$A."&ProductID=".$P."&n=".$N."'>
<img src='img/note_add.png' width='22' height='22' /></a>"; ?></td>
<td align="center">
<script>
// ทดสอบการใช้ GET
function getData(){
$.get("get.php",
{ data: $("#data1").val()
},
function(data){
$("#divGetData").html(data);
}
);
}
</script>
<div id="divGetData">
<input name="data1<?php echo $i;?>" type="text" id="data1" size="40" value="<?php echo $row["ProductID"]; ?>" />
<input type="button" name="Button1<?php echo $i;?>" id="button1" value="Get" onclick="getData()" />
</div>
</td>
</tr>
<?php } ?>
</table>
</div>
</form>
</body>
</html>
<?php } ?>
<?php
ob_end_flush();
mysql_close($d1,$db1,$c1);
mysql_close($d2,$db2,$c1);
exit();
?>
ได้แบบนี้
|
|
|
|
|
Date :
2017-11-29 08:56:17 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
ob_start();
session_start();
require('include/db_connect.php');
require('include/function.php');
if($_SESSION['lL'] == 1)
{
$SQl="SELECT product_list.Auto,
product_list.ProductID,
product_list.ProductIDList,
asset_dept.AssetDeptName,
asset_dept.AssetDeptID,
product_list.location,
product_list.QTY,
group_asset.GroupName,
group_asset.GroupID,
product_list.DateCreate,
product_list.DateEX,
using.UseID,
using.UseName,
product_list.Remark,
product_list.AdminID,
product_list.DeptID
FROM stock_supplies.product_list
LEFT JOIN stock_supplies.asset_dept ON asset_dept.AssetDeptID = product_list.AssetDeptID
LEFT JOIN stock_supplies.group_asset ON group_asset.GroupID = product_list.GroupID
LEFT JOIN stock_supplies.using ON using.UseID = product_list.UseID
WHERE product_list.ProductID ='".$_GET['data']."'
ORDER By product_list.ProductIDList ";
}else{
$SQl="SELECT product_list.Auto,
product_list.ProductID,
product_list.ProductIDList,
asset_dept.AssetDeptName,
asset_dept.AssetDeptID,
product_list.location,
product_list.QTY,
group_asset.GroupName,
group_asset.GroupID,
product_list.DateCreate,
product_list.DateEX,
using.UseID,
using.UseName,
product_list.Remark,
product_list.AdminID,
product_list.DeptID
FROM stock_supplies.product_list
LEFT JOIN stock_supplies.asset_dept ON asset_dept.AssetDeptID = product_list.AssetDeptID
LEFT JOIN stock_supplies.group_asset ON group_asset.GroupID = product_list.GroupID
LEFT JOIN stock_supplies.using ON using.UseID = product_list.UseID
WHERE product_list.ProductID ='".$_GET['data']."' AND product_list.DeptID ='".$_SESSION['lDeptID']."'
ORDER By product_list.ProductID ";
}
$ser=mysql_query($SQl) or die("Show Errors Detail ::".mysql_error());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE; ?></title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/textcss.css" type="text/css" rel="stylesheet" >
<link href="css/styleinput.css" type="text/css" rel="stylesheet" >
<link href="css/stylelink.css" type="text/css" rel="stylesheet">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<link rel="stylesheet" type="text/css"
href="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.css" />
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js"> </script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.9.2.custom/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
<body>
<form action="" name="test" id="test" method="post">
<div id="DivD">
<input type="button" name="ok<?php echo $i;?>" id="ok" value="Show/Hide"/>
<input type="submit" name="ok<?php echo $i;?>" id="ok" value="Back" />
<script>
$(function(){
$("#ok").click(function(){
$("#DivD").toggle("slow");
});
});
</script>
<table width="96%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="11" align="center"> Show </td>
</tr>
<tr>
<td> ລຳດັບ</td>
<td> ProductID</td>
<td> ProductIDList</td>
<td> AssetDeptName</td>
<td> location</td>
<td> QTY</td>
<td> GroupName</td>
<td> DateCreate</td>
<td> DateEX</td>
<td> UseName</td>
<td> Remark</td>
</tr>
<?php
$i=0;
while($d=mysql_fetch_assoc($ser))
{
++$i;
?>
<tr>
<td> <?php echo $i?><input type="hidden" name="h1" id="h1" value="<?php echo $d["Auto"]?>"></td>
<td> <?php echo $d["ProductID"]?><input type="hidden" name="ProductIDS" id="ProductIDS" value="<?php echo $d["ProductID"]?>"></td>
<td> <?php echo $d["ProductIDList"]?></td>
<td> <?php echo $d["AssetDeptName"]?></td>
<td> <?php echo $d["location"]?></td>
<td> <?php echo $d["QTY"]?></td>
<td> <?php echo $d["GroupName"]?></td>
<td> <?php echo $d["DateCreate"]?></td>
<td> <?php echo $d["DateEX"]?></td>
<td> <?php echo $d["UseName"]?></td>
<td> <?php echo $d["Remark"]?></td>
<?php } ?>
</tr>
</table>
</div>
</form>
แก้แบบนี้ แต่มันไม่ วนลูบ ให้ครับ แก้แบบไหนดี ไปไม่เป็น
|
|
|
|
|
Date :
2017-11-29 08:57:31 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
......
|
|
|
|
|
Date :
2017-11-29 13:30:02 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|