|
 |
|
ต้องการบันทึกข้อมูลจาก function JavaScript ทำได้ไหมค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
include("inc/config.php");
conndb();
// ลบ subfile ในโฟลเดอร์หัวเรื่อง
$sqldata= "select *from tb_subfile where file_id = '20120417112002'";
$querydata = mysql_query($sqldata) or die("error=$sqldata");
$numdata = mysql_num_rows($querydata);
$resultid_data = array();
if($numdata!=0)
{
while($rowdata = mysql_fetch_array($querydata))
{
array_push($resultid_data,$rowdata['subf_name']);
}
}
for($i;$i<$numdata;$i++){
$resultid_data[0];
$resultid_data[1];
$resultid_data[2];
$resultid_data[3];
$resultid_data[4];
}
?>
<!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>Untitled Document</title>
</head>
<body>
<form action="test2.php" method="post">
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>No.</td>
<td>NAME</td>
</tr>
<tr>
<td><?=$no++;?></td>
<td><a href="test/<?=$resultid_data[0];?>" onclick="send1();" target="_blank"><?=$resultid_data[0];?></a><br />
<a href="test/<?=$resultid_data[1];?>" onclick="send2();"target="_blank"><?=$resultid_data[1];?></a><br />
<a href="test/<?=$resultid_data[2];?>" onclick="send3();"target="_blank"><?=$resultid_data[2];?></a><br />
<a href="test/<?=$resultid_data[3];?>" onclick="send4();"target="_blank"><?=$resultid_data[3];?></a><br />
<a href="test/<?=$resultid_data[4];?>" onclick="send5();"target="_blank"><?=$resultid_data[4];?></a></td>
</tr>
</table>
</form>
<SCRIPT LANGUAGE="JavaScript">
function send1() {
alert("<?
$s1 = $resultid_data[0];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s1')";
$querylog = mysql_query($slog);
echo "SHOW ".$s1;
?>");
return true;
}
function send2() {
alert("<?
$s2 = $resultid_data[1];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s2')";
$querylog = mysql_query($slog);
echo "SHOW ".$s2;
?>");
return true;
}
function send3() {
alert("<?
$s3 = $resultid_data[2];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s3')";
$querylog = mysql_query($slog);
echo "SHOW ".$s3;
?>");
return true;
}
function send4() {
alert("<?
$s4 = $resultid_data[3];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s4')";
$querylog = mysql_query($slog);
echo "SHOW ".$s4;
?>");
return true;
}
function send5() {
alert("<?
$s5 = $resultid_data[4];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s5')";
$querylog = mysql_query($slog);
echo "SHOW ".$s5;
?>");
return true;
}
</script>
</body>
</html>
---------------
ตอนเรียกค่าแสดงผลมันก้อขึ้นชื่อไฟล์ตรงกับที่เลือกแต่พอจะบันทึกมันไม่บันทึกให้ จะบันทึกตอนเรากด รีเฟรชหน้าจอ งงมากเลยค่ะ รบกวนผู้รู้หน่อยคะ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-04-17 15:06:37 |
By :
cikkarat |
View :
1375 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบ่งการทำงานออกเป็นสองไฟล์น่ะครับ
Code (PHP)
<?
include("inc/config.php");
conndb();
//https://www.thaicreate.com/php/forum/077134.html
// ลบ subfile ในโฟลเดอร์หัวเรื่อง
$sqldata= "select *from tb_subfile where file_id = '20120417112002'";
$querydata = mysql_query($sqldata) or die("error=$sqldata");
$numdata = mysql_num_rows($querydata);
$resultid_data = array();
if($numdata!=0)
{
while($rowdata = mysql_fetch_array($querydata))
{
array_push($resultid_data,$rowdata['subf_name']);
}
}
?>
<!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>Untitled Document</title>
</head>
<body>
<form action="test2.php" method="post">
<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>No.</td>
<td>NAME</td>
</tr>
<tr>
<td><?=$no++;?></td>
<td><a href="test/<?=$resultid_data[0];?>" onclick="send(<?=$resultid_data[0];?>)"><?=$resultid_data[0];?></a><br />
<a href="test/<?=$resultid_data[1];?>" onclick="send(<?=$resultid_data[1];?>);"><?=$resultid_data[1];?></a><br />
<a href="test/<?=$resultid_data[2];?>" onclick="send(<?=$resultid_data[2];?>);"><?=$resultid_data[2];?></a><br />
<a href="test/<?=$resultid_data[3];?>" onclick="send(<?=$resultid_data[3];?>);"><?=$resultid_data[3];?></a><br />
<a href="test/<?=$resultid_data[4];?>" onclick="send(<?=$resultid_data[4];?>);"><?=$resultid_data[4];?></a></td>
</tr>
</table>
</form>
<div id="resultShow" style="color:red;"></div>
<SCRIPT LANGUAGE="JavaScript">
function send(input) {
$.post('save_resultid_data.php',{resultid_data:input}, function(data) {
$('#resultShow').html(data);
});
}
</script>
</body>
</html>
ส่วนไฟล์ที่สองให้ตั้งชื่อว่า save_resultid_data.php
Code (PHP)
<?php
include("inc/config.php");
conndb();
$s = $_POST["resultid_data"];
$slog = "INSERT INTO testlog";
$slog .= "(logID,logDate,logStatus,logSubfname) VALUES";
$slog .= "('',NOW(),'เปิดดูเอกสาร','$s')";
$querylog = mysql_query($slog) or die(mysql_error().":".$slog);
echo "SHOW ".$s;
?>
|
 |
 |
 |
 |
Date :
2012-04-17 16:15:26 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำตามแล้วค่ะแต่ไม่ไม่บันทึกให้อ่ะคะ
|
 |
 |
 |
 |
Date :
2012-04-18 09:01:51 |
By :
cikkarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<SCRIPT LANGUAGE="JavaScript">
function send(input) {
$.post('save_resultid_data.php',{resultid_data:input}, function(data) {
$('#resultShow').html(data);
});
}
</script>
#resultShow คือค่ะอะไรหรือค่ะ
|
 |
 |
 |
 |
Date :
2012-04-18 13:16:59 |
By :
cikkarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ ajax ใน JQuery ไม่ยากอย่างที่คิด
|
 |
 |
 |
 |
Date :
2012-04-18 17:11:34 |
By :
tonyjame |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้แล้วค่ะ ขอบคุณทุกคอมเม้นนะค่ะ
|
 |
 |
 |
 |
Date :
2012-04-19 08:13:53 |
By :
cikkarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|