|
|
|
กดปุ่ม button แล้ว ส่งข้อมูลได้แต่ ลูปบนอย่างเดียว เป็นการส่งแบบ ajax |
|
|
|
|
|
|
|
ตามโค้ดนี้เลยครับ รู้สึกมันจะรู้จัก button เดียว ทำให้มันรู้จักแต่ละ วนลูป ยังไงด้ครับ
Code (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></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn1").click(function(){
$.ajax({
url: "saveData.php" ,
type: "POST",
datatype: "json",
data: 'keyword={"'+$("#txtimage").val()+'","'+$("#txtid").val()+'" ,"'+$("#txtdiscription").val()+'" ,"'+$("#txtprice").val()+'"}'
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj.status == true)
{
alert('Chaiyo !!! ' + obj.msg);
}
else
{
alert('Sadddddd !!! ' + obj.msg);
}
});
});
});
</script>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","784512") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM tb_linkpage1 where password = 22222222 order by id desc limit 5 ";
$objQuery = mysql_query($strSQL)or die ("Error Query [".$strSQL."]");
?>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td width="50" align="center" bgcolor="#FF99CC">#</td>
<td width="80" bgcolor="#FF99CC">Picture</td>
<td height="20" bgcolor="#FF99CC">Topic</td>
<td width="80" bgcolor="#FF99CC">price</td>
<td width="50" bgcolor="#FF99CC">edit</td>
</tr>
<?
$i=1;
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr bgcolor="#CCCC99" style="cursor:pointer;">
<td align="center" bgcolor="#EBEBD8"><?=$i?></td>
<td width="70" bgcolor="#EBEBD8"><div align="center"><a href="link_1.php?CusID=<?=$objResult["password"];?>&ID=<?=$objResult["image"];?>"><img src="myfile/<?=$objResult["image"];?>" width="120" heigth="50"></a></div></td>
<td height="20" bgcolor="#EBEBD8"><?=$objResult["discription"];?><?=$i?></td>
<td height="20" bgcolor="#EBEBD8"><?=$objResult["price"];?></td>
<td height="20" align="center" bgcolor="#EBEBD8" onclick="$('#tr_toggle<?=$i?>').toggle();" >EDIT</td>
</tr>
<tr style="display:none;" id="tr_toggle<?=$i?>">
<td bgcolor="#F8F8EF">
</td>
<td align="left" bgcolor="#F8F8EF">
<input type="file" id="txtimage" size="1"/>
<input type="hidden" id="txtid" value="<?=$objResult["ID"];?>" />
</td>
<td align="left" bgcolor="#F8F8EF">
<input type="text" id="txtdiscription" size="8" value="<?=$objResult["discription"];?>" /><?=$i?>
</td>
<td align="left" bgcolor="#F8F8EF">
<input type="text" id="txtprice" size="2" value="<?=$objResult["price"];?>" />
</td>
<td align="center" bgcolor="#F8F8EF">
<input type="button" id="btn1" value="Save">
</td>
</tr>
<?
$i++;
}
?>
</table>
<?
mysql_close($objConnect);
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</body>
</html>
Tag : PHP, Ajax, jQuery
|
|
|
|
|
|
Date :
2012-10-13 19:33:40 |
By :
BABANGYAI |
View :
936 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id ของแต่ละ Element มันซ้ำกัน
|
|
|
|
|
Date :
2012-10-14 00:31:06 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ code อะไรแยกได้ครับ
|
|
|
|
|
Date :
2012-10-14 16:47:26 |
By :
BABANGYAI |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|