Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > สอบถาม : การบันทึกข้อมูลลง mySQL ด้วย PHP แบบนี้ทำอย่างไรครับ



 

สอบถาม : การบันทึกข้อมูลลง mySQL ด้วย PHP แบบนี้ทำอย่างไรครับ

 



Topic : 115353



โพสกระทู้ ( 25 )
บทความ ( 0 )



สถานะออฟไลน์




คืออยากจะบันทึกข้อมูลลง mySQL แต่ปัญหามันติดตรงที่ว่า
1. ข้อมูลผม มีหลาย column เเละ หลาย row
1

2. ผมอยากจะบันทึกข้อมูลแต่ละครั้งลง SQL ใน row เดียว โดยใน 1 Table จะมีแค่ 3 colum คือ ID ลำดับของข้อมูล, DETAIL รายละเอียดข้อมูลผม, DATE วันที่บันทึกข้อมูล ผมจะบันทึกลงไปอย่างไร หรือจะปรับเปลี่ยนอย่างไร

3. ผมอยากจะดึงข้อมูลใน SQL ใน คอลั่ม DETAIL มาแสดงเป็นตารางเหมือนกับตอนบันทึกข้อมูล ทำได้ไหมครับ เเล้วทำอย่างไรครับ

สรุป อยากบันทึกข้อมูลทั้งหมดหลายๆ colum หลายๆ row เเละนำมาแสดง ในรูปแบบขอตารางแบบเดิม

ขอบพระคุณครับ

นี่ code ครับ

Code
<html>
<head>
</head>
<script language="javascript">
function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;

var theTable = document.all.tbExp
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID

var item1 = 1
var newCell

//*** Column 1 ***//
newCell = newRow.insertCell(0)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column1_"+intLine+"\" VALUE=\"\"></center>"

//*** Column 2 ***//
newCell = newRow.insertCell(1)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column2_"+intLine+"\" VALUE=\"\"></center>"

//*** Column 3 ***//
newCell = newRow.insertCell(2)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column3_"+intLine+"\" VALUE=\"\"></center>"

//*** Column 4 ***//
newCell = newRow.insertCell(3)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" VALUE=\"\"></center>"

//*** Column 5 ***//
newCell = newRow.insertCell(4)
newCell.id = newCell.uniqueID
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column5_"+intLine+"\" VALUE=\"\"></center>"

document.frmMain.hdnMaxLine.value = intLine;
}

function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = (document.all) ? document.all.tbExp :
document.getElementById("tbExp")
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>
<body>
<form name="frmMain" method="post" action="insert.php">
<table width="445" border="1" id="tbExp">
<tr>
<td><div align="center">Column 1 </div></td>
<td><div align="center">Column 2 </div></td>
<td><div align="center">Column 3 </div></td>
<td><div align="center">Column 4 </div></td>
<td><div align="center">Column 5 </div></td>
</tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
</form>
</body>
</html>




Tag : PHP









ประวัติการแก้ไข
2015-03-24 10:05:45
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-03-24 10:02:21 By : mtts10448 View : 1258 Reply : 10
 

 

No. 1



โพสกระทู้ ( 3,844 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

ลอง action from แล้ว var_dump($_POST) ดูครับ คิดว่าน่าจะมองออกว่าควรจะรับค่ายังไง






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 11:23:13 By : mangkunzo
 


 

No. 2

Guest


ยัง งง คร้บ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 11:27:13 By : mtts10448
 

 

No. 3

Guest


ขอตัวอย่างก็ดีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 11:46:14 By : mtts10448
 


 

No. 4



โพสกระทู้ ( 1,666 )
บทความ ( 0 )



สถานะออฟไลน์


เอา $_POST มาจับรวมกันคั่นด้วยคอมม่าหรืออักษรที่เป็นเอกลักษณ์อะไรก็ได้ แล้วก็ Insert ลงไปตามปกคิครับ

***เดาว่าข้อมูลทั้ง 5 ช่องคงเป็นข้อมูลของฟิลล์ DETAIL ไช่รึเปล่าครับ

1. หาวิธีรับค่าทั้งหมดให้ได้ และแสดงผลแบบง่ายๆก่อน
2. หาวิธีเชื่อมค่าทั้งหมดที่ได้แล้วคั่นด้วยคอมม่า(หรืออักษรที่เป็นเอกลักษณ์)
3. เมื่อรวมกันไว้ในตัวแปรเดียวแล้ว ก็ INSERT ลงฐานข้อมูลตามปกติ

**ตอนนำกลับมาแสดงผลค่อยคิดอีกทีมันมีวิธีอยู่แล้วไม่ต้องห่วง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 11:59:08 By : meannerss
 


 

No. 5

Guest


ใช่แล้วครับรวมทั้ง row ต่อไปๆที่กดเพิ่มด้วยคับเอาไปไส่ detail หมดเลยคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 12:53:16 By : Mtts10447
 


 

No. 6

Guest


ยังไม่ได้ไครก้อได้ช่วยทีครับบบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 13:54:13 By : mtts10448
 


 

No. 7



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

แพคข้อมูล เวลาบันทึก เวลาจะใช้ก็แกะออกมา
วิธีง่ายๆ ก็ serialize()/unserialize()

เวลาใช้ก็ unpack ด้วย unserialize()

http://php.net/manual/en/function.serialize.php
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 14:02:47 By : pjgunner.com
 


 

No. 8

Guest


ผมเอามันออกมาแสดงได้แล้วครับ แต่ผมยังเอาไปใสใน Database ไม่เป็นครับ
สมมุตรนะครับ จะเอาไปไส่ในตาราง fixture เเล้วในคอลั่ม FixtureDetail ผมจะเอามันไปยังไง เเล้วดึงมันออกมายังไง งง จริงๆครับ


Script.php
Code
<script language="javascript">

function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;

var theTable = document.getElementById("tbExp");
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID

var newCell


newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center>"+intLine+"</center>";


newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"type_id[]\" SIZE=\"5\" ID=\"type_id"+intLine+"\" VALUE=\"\"></center>";

newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"type_name[]\" ID=\"type_name"+intLine+"\" VALUE=\"\"></center>";

//*** Column color_name ***//
newCell = newRow.insertCell(3);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"color_name[]\" ID=\"color_name"+intLine+"\" VALUE=\"\"></center>";

newCell = newRow.insertCell(4);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"unit[]\" ID=\"unit"+intLine+"\" VALUE=\"\"></center>"

newCell = newRow.insertCell(5);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"amount[]\" ID=\"amount"+intLine+"\" VALUE=\"\"></center>";

newCell = newRow.insertCell(6);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"price[]\" ID=\"price"+intLine+"\" VALUE=\"\"></center>";
document.frmMain.hdnMaxLine.value = intLine;

}
function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = document.getElementById("tbExp");
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>


Fixtures_insert.php
Code
<?php include("script.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>
</head>
</html>
<body OnLoad="CreateNewRow()">
<form name="frmMain" method="post" action="fixture_save.php">
<table height="78" border="1" id="tbExp" cellpadding="0" cellspacing="0" style="font-size:13px; ">
<tr>
<th width="40"><div align="center">ลำดับ </div></th>
<th width="80"><div align="center">COL 1 </div></th>
<th width="40"><div align="center">COL 2 </div></th>
<th width="80"><div align="center">COL 3 </div></th>
<th width="30"><div align="center">COL 4 </div></th>
<th width="30"><div align="center">COL 5 </div></th>
<th width="100"><div align="center">COL 6</div></th>
</tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0" >
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
<input type="submit" name="btnSubmit" value="บันทึกข้อมูล" />
</form>
<script language="javascript">
CreateNewRow();
</script>


Fixtures_save.php
Code
<table height="78" border="1" id="tbExp" cellpadding="0" cellspacing="0" style="font-size:13px; ">
<tr>
<th width="80"><div align="center">COL 1 </div></th>
<th width="40"><div align="center">COL 2 </div></th>
<th width="80"><div align="center">COL 3 </div></th>
<th width="30"><div align="center">COL 4 </div></th>
<th width="30"><div align="center">COL 5 </div></th>
<th width="100"><div align="center">COL 6</div></th>
</tr>

<?php
foreach($_POST["type_id"] as $key=>$typeId)
{
echo "<tr><th>" ,$_POST["type_id"][$key],"</th>";
echo "<th>" ,$_POST["type_name"][$key],"</th>";
echo "<th>" ,$_POST["color_name"][$key],"</th>";
echo "<th>" ,$_POST["unit"][$key],"</th>";
echo "<th>" ,$_POST["amount"][$key],"</th>";
echo "<th>" ,$_POST["price"][$key],"</th>";
echo "</tr>";
}
?>

</table>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 17:40:16 By : mtts10448
 


 

No. 9



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


Code (PHP)
<?php
foreach($_POST["type_id"] as $key=>$typeId)
{
echo "<tr><th>" ,$_POST["type_id"][$key],"</th>";
echo "<th>" ,$_POST["type_name"][$key],"</th>";
echo "<th>" ,$_POST["color_name"][$key],"</th>";
echo "<th>" ,$_POST["unit"][$key],"</th>";
echo "<th>" ,$_POST["amount"][$key],"</th>";
echo "<th>" ,$_POST["price"][$key],"</th>";
echo "</tr>";
 

//เอาจากข้างบนมาใช้ generate เป็น HTML ได้ ก็ควรจะ generate เป็น sql statement ได้

$p = $_POST;
$sql = <<<SQL
insert into table 
set type_id=$p[type_id][$key]
, type_name='$p['type_name][$key]'
, field อื่นๆ .........
SQL;
msyql_query( $sql );
}
?>



ประวัติการแก้ไข
2015-03-24 17:59:21
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-24 17:58:07 By : Chaidhanan
 


 

No. 10

Guest


ยังไม่ได้ครับ ยังไปไม่ถูกอยู่เลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-03-25 10:08:28 By : mtts10448
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม : การบันทึกข้อมูลลง mySQL ด้วย PHP แบบนี้ทำอย่างไรครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่