 |
ขอถามต่อเนื่องครับ มีตาราง 2 ตาราง ครับ ต้องการเอามา Show ในหน้าเดียวกันต้องทำยังไงครับ |
|
 |
|
|
 |
 |
|
ก็ คิวรี่ 2 ครั้ง แหละคับ
ตารางทั้ง 2 ต้องมีความสัมพันธ์กัน เช่น ตาราง file เก็บ รหัสของตาราง content ไว้ด้วย
เริ่มต้นก็ query content ออกมาก่อน แล้วเอาค่า รหัส ไป คิวรรี่หาใน ตารางไฟล์อีกที
|
 |
 |
 |
 |
Date :
2015-11-14 12:49:53 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าเราทำให้ ตารางสัมพันธ์กัน ใน MySQL ต้องทำยังไงหรอครับ อันนี้เคยทำแค่ตารางเดียวครับ แต่ตัวอย่างมี 2 ตารางครับ
|
 |
 |
 |
 |
Date :
2015-11-14 13:41:34 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าต้องการให้คิวรี่แบบเชื่อมโยงสองตารางใช้การ JOIN ครับ
https://www.thaicreate.com/tutorial/sql-left-join.html
|
 |
 |
 |
 |
Date :
2015-11-14 13:46:01 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สัมพันกันยังไง
table content เวลาเก็บข้อมูลหลักๆมันจะเป็น
id , ชื่อ , และฟิลอื่นๆ
table file ถ้าจะให้สัมพันกับตาราง content ก็ต้องประมาณ
id , content_id , ชื่อ และฟิวอื่น
เวลาเพิ่มข้อมูลลงไปมันจะประมาณ
table content
id , name
1 ข่าวสาร
2 ทดสอบ
3 ข่าวสารทดสอบ
table file
id , content_id name
1 1 file.png
2 1 file2.png
3 2 test.jpg
4 3 test5.jpg
เวลาคิวรี่
Code (SQL)
$sql = select * from content
while($row = xxxxx()){
$content_id = $row['id'];
echo "Content ID ".$content_id." ชื่อ ".$row['name'];
$sql2 = select * from file where content_id = $content_id;
while($row2 = xxxxx()){
echo "มีไฟล์ชื่อ".$row2['name'];
}
}
คิวรี่ตัวอย่างนะคับ ไปลองปรับใช้ดู
|
 |
 |
 |
 |
Date :
2015-11-14 13:57:13 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากนะครับ ที่ตอบครับ ตอนนี้งงมากๆเลยครับ ตอนแรกก๋จะเสร็จแล้วทำไปทำมา ไม่ได้ซะงั้น จับจุดไม่ถูกครับ
|
 |
 |
 |
 |
Date :
2015-11-14 14:20:01 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้นะครับ พี่ progamer2000

อันนี้ Code ที่ผมดัดแปลงมาครับ
Code (PHP)
<title>
Pissanu Pongoubon Test
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
// ???????????????????
$host="localhost"; // ????? host
$username="root"; // ????? username
$pass_word="root"; // ????? Password
$db="mydatabase"; // ??????????????????
$Conn = mysql_connect( $host,$username,$pass_word) or die ("?????????????????????");// ???????????????
mysql_query("SET NAMES utf8",$Conn); // set ?????????????
mysql_select_db($db) or die("????????????????????"); // ??????????????
//--->
{
$del_FilesID = @$_REQUEST['del_FilesID'];
$sql_del = "delete from files where FilesID = '$del_FilesID';";
mysql_query($sql_del) or die(mysql_error());
}
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
?>
<style type="text/css">
<!--
a:link {
color: #0000FF;
text-decoration: none;
}
a:visited {
color: #0000FF;
text-decoration: none;
}
a:hover {
color: #0000FF;
text-decoration: none;
}
a:active {
color: #0000FF;
text-decoration: none;
}
body,td,th {
color: #000000;
}
body {
background-color: #99FFCC;
}
.style6 {color: #FF0000}
.style7 {
font-size: 18px;
font-weight: bold;
}
.style9 {color: #0000FF}
.style15 {color: #000000}
.style16 {font-size: 12px}
.style17 {font-size: 16px}
-->
-->login
-->
</style>
<table width="2542" height="100" border="1">
<tr>
<td width="200" height="100"><table width="228" border="1" style="width: 250
px">
<tbody>
<tr>
<td width="84"> Username</td>
<td width="128"><?php echo $objResult["Username"];?> <div align="center"></div></td>
</tr>
<tr>
<td height="23"> Name</td>
<td><?php echo $objResult["Name"];?></td>
</tr>
</tbody>
</table>
<a href="file:///C|/xampp/htdocs/edit_profile.php">Edit</a><br />
<a href="file:///C|/xampp/htdocs/logout.php">Logout</a></td>
<td width="2326"> </td>
</tr>
</table>
<table width="2542" height="55" border="1">
<tr>
<td width="265" height="49"><img src="file:///C|/xampp/htdocs/Img/A.jpg"width="275" height="45" /></td>
<td width="2261"><table width="597" border="1"cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<tr>
<th width="393" height="40" align="center" ><form id="form1" name="form1" method="post" action="show.php"><div align="center">search
<input name="txt_search" type="text" value="<?=$_POST['txt_search']?>" />
<input name="Search" type="submit" value="search" />
</div>
</form></th>
<th width="84" scope="col"><a href="add_form.php?edit_id=<?=$row_show[id]?>">Add data</a></th>
<th width="98" scope="col">
<!--#print Previwe -->
<script language="javascript">
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
<input name="btnPrint" type="button" id="btnPrint" value="Print" onClick="JavaScript:this.style.display='none';printpr();"></th>
</tr>
</table></td>
</tr>
</table>
<table width="2544" border="1">
<tr>
<th width="154" rowspan="2" valign="top" scope="col"> </th>
<th width="2374" align="left" valign="top" scope="col">
<?PHP
#ฟังก์ชั่นนี้ใช้สำหรับ Rename ชื่อไฟล์ที่ทำการอัพโหลดใหม่ รับค่า $_FILES['file']['name']
#ผลลัพธิ์จะได้ เช่น รับค่า ทดสอบ.docx ฟังก์ชั่นจะส่งค่ามาเป็น Acdeq12345678.docx เป็นต้น
function getNewName($fileName){
$fileName = explode('.',$fileName);
$i = count($fileName)-1;
$fileType = strtolower($fileName[$i]);
$rand = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),0,5);
$result = $rand.time().'.'.$fileType;
return $result;
}
$db = new mysqli("localhost", "root", "root", "mydatabase");
$db->set_charset("utf8");
/* check connection */
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
exit();
}
if(!empty($_POST['button'])){
$content_title = !empty($_POST['content_title']) ? $_POST['content_title'] : NULL;
$content_detail = !empty($_POST['content_detail']) ? $_POST['content_detail'] : NULL;
$description = !empty($_POST['description']) ? $_POST['description'] : NULL;
if(!empty($content_title)){
$db->query(" INSERT INTO tbl_content( content_name,content_detail,description ) VALUES( '$content_title', '$content_detail', '$description' ) "); #บันทึกลงฐานข้อมูล
$lastId = $db->insert_id; # ID ล่าสุดที่ทำการบันทึก และนำไปอ้างอิงในตารางที่เก็บไฟล์แนบ
if(!empty($lastId)){
for($i=1;$i<=5;$i++){
$file_title = $_POST['filename_'.$i];
$file_name = $_FILES['files_'.$i]['name'];
$file_tmp = $_FILES['files_'.$i]['tmp_name'];
$part = 'uploads/';
if( !empty($file_title) && !empty($file_name) ) {
$newFileName = getNewName($file_name);
if (move_uploaded_file($file_tmp, $part.$newFileName)) {
$db->query(" INSERT INTO tbl_files( ref_content_id, files_title, files_name ) VALUES( '$lastId', '$file_title', '$newFileName' ) "); #บันทึกลงฐานข้อมูล
}
}
} #End for()
echo 'Success';
} #End if(!empty($lastId))
} #End if(!empty($content_title))
} #End if(!empty($_POST['button']))
?>
<form enctype="multipart/form-data" method="post">
<table width="690" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="34" colspan="2" scope="row">Material master mapping</th>
</tr>
<tr>
<th height="31" colspan="2" align="left" scope="row"> Itemp :
<input type="text" name="content_title" id="content_title" size="44" /></th>
</tr>
<tr>
<tr>
<th height="31" colspan="2" align="left" scope="row"> Description :
<input type="text" name="description" id="description" size="44" /></th>
</tr>
<tr>
<th width="320" height="28" bgcolor="#FFFFCC" scope="row">ชื่อไฟล์</th>
<th width="370" bgcolor="#FFFFCC" scope="row">แนบไฟล์</th>
</tr>
<?PHP for($i=1;$i<=5;$i++){ ?>
<tr>
<th height="32" scope="row"><input name="filename_<?PHP echo $i; ?>" type="text" id="filename_<?PHP echo $i; ?>" size="50" /></th>
<th scope="row"><input type="file" name="files_<?PHP echo $i; ?>" id="files_<?PHP echo $i; ?>" /></th>
</tr>
<?PHP } ?>
<tr>
<th colspan="2" scope="row" height="45"><p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
<p> </p></th>
</tr>
</table>
</form>
<table width="902" border="1" cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<br>
<tr>
<td width="87"><div align="center" class="style6"> Itemp</div></td>
<td width="83"><div align="center" class="style6">Description</div></td>
<td width="146"><div align="center" class="style6">Picture1</div></td>
<td width="152"><div align="center" class="style6">Picture2</div></td>
<td width="83"><div align="center" class="style6">Picture3</div></td>
<td width="80"><div align="center" class="style6">Picture4</div></td>
<td width="88"><div align="center" class="style6">Picture5</div></td>
<td width="90"><div align="center" class="style6">delete</div></td>
<td width="213"><div align="center" class="style6">edit</div></td>
</tr>
<?php
$sql_show = "select * from tbl_content";
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
?>
<?php
$sql_show = "select * from tbl_content";
if($_POST['Search'])
{
$txt_search = $_POST['txt_search'];
$sql_show.=" where '%$txt_search%' or item like '%$txt_search%' or item like '%$txt_search%' or description like '%$txt_search%' or model like '%$txt_search%' ";
}
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
{
?>
<tr>
<td><div align="center"><?=$row_show['content_name']?></div></td>
<td><div align="center"><?=$row_show['description']?></div></td>
<td><div align="center"><?=$row_show['files_name ']?></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><a href="show.php?del_FilesID=<?=$row_show[FilesID]?>"onclick="return confirm('Are you sure you want to delete')">delete</a></div></td>
<td><div align="center"><a href="show.php?del_id=<?=$row_show[id]?>">edit</a></div></td
>
</tr>
<script language="JavaScript">
function Conf<? echo "$FilesID" ?>(object)
{
if (confirm("Do you want to delete [ <? echo " $FilesID " ?> ] ?") ==true)
{
return true;
}
return false;
}
</font>
</script>
<?php
}
?>
</table>
<br>
<table width="597" border="1"cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<tr>
<th width="393" height="40" align="center" >
</body>
</html>
อันนี้ my SQL ครับ


น้ำตาจะไหล งงไปหมดแล้วครับ
|
 |
 |
 |
 |
Date :
2015-11-14 15:11:29 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใน code มีอะไรมาเต็มไปหมด
เชื่่อมต่อ db มีหลาย รูปแบบเหลือเกิน แบบบนสุดเชื่อมแบบเก่า ล่างๆ เชื่อมแบบ mysqli
การเขียน code ดูสับสน ยุ่งเหยิง ประมาณ จะเพิ่ม ฟังชั่น เพิ่ม css ใช้ตรงไหนก็เพิ่มตรงนั้นไปซะหมด 5555
อยากให้ปรับปรุงการเขียน code ให้เป็น pattern มากกว่านี้นะคับ เวลาอนาคตแก้งาน มันจะง่ายในการดู
ดึกๆผมถึงจะมาช่วยได้งะ ตอนนี้ยังไม่สะดวก เชค code ให้เลย
|
 |
 |
 |
 |
Date :
2015-11-14 15:21:34 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆๆ ครับ น้ำตาจะไหลเลยครับ
|
 |
 |
 |
 |
Date :
2015-11-14 16:24:32 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผม ดู code ละ คิดว่า หน้านี้ มันมี code อะไรไม่รู้ แทรกอยู่เต็มไปหมด มี สำหรับค้นหาด้วย ด้านบน
ผมเลย งง ว่า ที่ แปะ code มานิ คือ ใช้สำหรับหน้่านี้หรือเปล่า
ว่าแต่ ตอนนี้ติดตรงไหนนะคับ
|
 |
 |
 |
 |
Date :
2015-11-14 16:47:36 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จิงๆแล้ว ตัวค้นหาพิมทำได้ครับ แต่ผมยังไม่ได้ใส่ code ครับ เอามาเป็นแบบก่อน ที่ติดตอนนี้คือ ตามภาพที่ส่งให้ดูนะครับ เวลาใา่รูปภาพ แล้ว ใหชื่อ ขึ้นโชว์ที่ Pictrue 1 ตามลำดับถึง 5 ครับ ถ้าผมเดานะครับ อยากให้ ID มันเป็นอันเดียวกัน เพราะต้องมี ลบ ได้ด้วยครับ ตัวลบผม สร้างเองได้ครับ ขอแค่ให้ลบใน บรรทัดเดียวได้ครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2015-11-14 16:58:33 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (SQL)
$sql = select * from content
while($row = xxxxx()){
$content_id = $row['id'];
echo "Content ID ".$content_id." ชื่อ ".$row['name'];
$sql2 = select * from file where content_id = $content_id;
while($row2 = xxxxx()){
echo "มีไฟล์ชื่อ".$row2['name'];
}
}
ลองเอาไปปรับยังคับ
|
 |
 |
 |
 |
Date :
2015-11-14 17:16:47 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทาที่ครับที่ตอบมา ช้า พอดีว่าไปต่างจังงหวัดมาครับ ยังไม่ได้ลองครับ วันนี้จะลองดุครับ รบกวนด้วยนะครับ
|
 |
 |
 |
 |
Date :
2015-11-16 07:50:42 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วเราจะดึงตารางที่ 2 มาใช้ยังไงหรอครับ
|
 |
 |
 |
 |
Date :
2015-11-16 08:27:49 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql = "select * from tbl_content";
while($row = "ใส่อะไรหรอครับ"()){
$content_id = $row['id'];
echo "Content ID ".$content_id." ชื่อ ".$row['name'];
$sql2 = "select * from file where content_id = $content_id";
while($row2 = "ใส่อะไรหรอครับ"()){
echo "มีไฟล์ชื่อ".$row2['name'];
}
}
|
 |
 |
 |
 |
Date :
2015-11-16 08:32:45 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมขอเบอร์พี่ progamer2000 อย่าหาว่าอย่างโน้นอย่างนี้เลยนะครับ ผมมีน้ำใจเล็กๆน้อยตอบแทนครับ รบกวนช่วยแนะนำผมหน่อยนะครับ อยากคุยหลังไมค์มากกว่าครับ
|
 |
 |
 |
 |
Date :
2015-11-16 10:47:43 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรงที่ถามว่าใส่อะไร ก็ใส่ การคิวรี่ คำสั่ง sql ไงครับ
ผมขี้เกียจเขียนทั้งหมด แต่ตรงนั้น ๆ จริงๆ ก็ไม่น่างง นะคับ ><
อ้างอิง
Code (PHP)
$sql_show = "select * from tbl_content";
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
มันก็คือตรงส่วนนี้นั่นแหละ เพียงแต่ผมขี้เกียจเขียนทั้งหมด แค่นั้นเอง
|
 |
 |
 |
 |
Date :
2015-11-16 13:01:20 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาใหม่ครับ เดี่ยวผมออกแบบรูปแบบใหม่ก่อนนะครับ น่าจะง่ายกว่านี้ครับ
|
 |
 |
 |
 |
Date :
2015-11-16 14:58:45 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วตารางทั้ง 2 ตามรางต้องสัมพันธ์ กันด้วยมั้ยครับ
|
 |
 |
 |
 |
Date :
2015-11-16 14:59:34 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สัมพันธ์กันซิคับไม่งั้น มันดึงข้อมูลจากตารางไฟล์ไม่ได้นะ
|
 |
 |
 |
 |
Date :
2015-11-16 15:03:36 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวผมออกแบบใหม่ก่อนดีกว่าครับ สรุปผมขอเบอร์ได้มั้ยครับ
|
 |
 |
 |
 |
Date :
2015-11-16 15:17:07 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โทรคุยผมก็ช่วยอะไรไม่ได้อะคับผมไม่เห็น code
และผมไม่ได้รับงานด้วย อิอิ ><
|
 |
 |
 |
 |
Date :
2015-11-16 15:18:53 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอมีโค๊ดทำรูปแบบปรพมาณนี้มั้ยครับ

สร้างเป็น มาให้เลือกครับ แล้วพอ ค้นหา สามารถดึง ตัวที่เราค้นหามาลงที่ Qty แล้วสถานนะก็เปลี่ยนเป้น ok ครับ
แล้วก็ บันทึกเป็น 1 Form นะครับ พอมีมั้ยครับ
หรือว่าใช้ โค๊ดเดิมได้อยู่ครับ
|
ประวัติการแก้ไข 2015-11-16 15:46:55
 |
 |
 |
 |
Date :
2015-11-16 15:31:38 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
555 จะบอกว่าผม งง อะ
หน้าเสิช กับหน้าแสดงอยู่หน้าเดียวกันหรือคับ
เสิชเป็นรหัส ละ หลังจากนั้นไม่เข้าใจ ><
|
 |
 |
 |
 |
Date :
2015-11-16 15:53:07 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนเดิมดีกว่า ตอนนี้ผมยัง JOIN ตารางไม่ได้เลยครับ ยังงง อยู่เลยครับ
|
 |
 |
 |
 |
Date :
2015-11-16 16:05:05 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ตารางสัมพันกันมั้ยครับ


|
 |
 |
 |
 |
Date :
2015-11-16 16:19:17 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ถ้า ref_content_id เก็บ content_id จาก ตาราง tbl_content ก็ สัมพันธืกันแล้วครับ
|
 |
 |
 |
 |
Date :
2015-11-16 16:29:11 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วทำไมผมดึงลงมาใช้ไม่ได้อ่ะครับ
|
 |
 |
 |
 |
Date :
2015-11-16 16:41:43 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอ คิวรี่ สร้าง ตาราง พร้อมข้อมูลตัวอย่างหน่อยคับ จะเอามา สร้างตารางเทสในคอมดู
|
 |
 |
 |
 |
Date :
2015-11-16 16:44:16 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
$sql_show = "select * from tbl_content";
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
?>

|
 |
 |
 |
 |
Date :
2015-11-16 16:51:09 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมต้องการแบบนี้คับ
Code (SQL)
CREATE TABLE IF NOT EXISTS `test` (
`code` int(11) NOT NULL AUTO_INCREMENT,
`filUpload` varchar(255) NOT NULL DEFAULT '',
`item` varchar(255) NOT NULL DEFAULT '',
`description` varchar(255) NOT NULL DEFAULT '',
`txtName` varchar(255) NOT NULL DEFAULT '',
`times` time NOT NULL DEFAULT '00:00:00',
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- dump ตาราง `test`
--
INSERT INTO `test` (`code`, `filUpload`, `item`, `description`, `txtName`, `times`) VALUES
(1, '', ' รายการกระจกสะท้อนแสง', ' รายการกระจกสะท้อนแสง', '', '00:00:00'),
(2, '', 'กระจก', 'กระจก', '', '00:00:00');
|
 |
 |
 |
 |
Date :
2015-11-16 16:53:27 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วเลือกแบบนี้ตรงไหนหรอครับ ส่วนใหญ่ผมดึง แบบ SQL ออกมาแลยนะครับ เป็น ไฟล์ ZIP
|
 |
 |
 |
 |
Date :
2015-11-16 17:10:44 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
tbl_content
-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 16, 2015 at 11:14 AM
-- Server version: 5.6.21
-- PHP Version: 5.6.3
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `mydatabase`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbl_content`
--
CREATE TABLE IF NOT EXISTS `tbl_content` (
`content_id` int(5) NOT NULL,
`content_name` varchar(255) NOT NULL,
`content_detail` text NOT NULL,
`description` varchar(255) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_content`
--
INSERT INTO `tbl_content` (`content_id`, `content_name`, `content_detail`, `description`) VALUES
(1, 'e', '', 'e');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tbl_content`
--
ALTER TABLE `tbl_content`
ADD PRIMARY KEY (`content_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tbl_content`
--
ALTER TABLE `tbl_content`
MODIFY `content_id` int(5) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
tbl_files
-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 16, 2015 at 11:14 AM
-- Server version: 5.6.21
-- PHP Version: 5.6.3
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `mydatabase`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbl_files`
--
CREATE TABLE IF NOT EXISTS `tbl_files` (
`files_id` int(10) NOT NULL,
`content_id` varchar(255) NOT NULL,
`ref_content_id` int(5) NOT NULL COMMENT 'FK จากตาราง tbl_content',
`files_title` varchar(255) NOT NULL,
`files_name` varchar(25) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_files`
--
INSERT INTO `tbl_files` (`files_id`, `content_id`, `ref_content_id`, `files_title`, `files_name`) VALUES
(1, '1', 1, 'sfsf', 'RJUxz1447487443.jpg'),
(2, '', 2, 'sss', 'kD2Ml1447487512.jpg'),
(3, '', 3, 'sss', 'TnN4v1447487589.jpg'),
(4, '', 4, 'ddd', 'mxHp91447487606.jpg'),
(5, '', 5, 'yty', 'Vj9Ly1447487628.jpg'),
(6, '', 6, 'rrr', 'VYocq1447487715.jpg'),
(7, '', 7, 'rrr', 'bDNjL1447487727.jpg'),
(8, '', 8, 'uuu', 'oSaBs1447487744.jpg'),
(9, '', 9, 'fsafaf', 'MVJle1447488084.jpg'),
(10, '', 10, 'dss', '8lute1447488157.jpg');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tbl_files`
--
ALTER TABLE `tbl_files`
ADD PRIMARY KEY (`files_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tbl_files`
--
ALTER TABLE `tbl_files`
MODIFY `files_id` int(10) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=11;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
ผมดึงให้ทั้งหมดเลยแล้วกันนะครับ
|
 |
 |
 |
 |
Date :
2015-11-16 17:16:32 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอ code ปัจจุบันหน้าดังกล่าวด้วยจ้าา
|
 |
 |
 |
 |
Date :
2015-11-16 17:21:21 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<title>
Pissanu Pongoubon Test
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
// ???????????????????
$host="localhost"; // ????? host
$username="root"; // ????? username
$pass_word="root"; // ????? Password
$db="mydatabase"; // ??????????????????
$Conn = mysql_connect( $host,$username,$pass_word) or die ("?????????????????????");// ???????????????
mysql_query("SET NAMES utf8",$Conn); // set ?????????????
mysql_select_db($db) or die("????????????????????"); // ??????????????
//--->
{
$del_FilesID = @$_REQUEST['del_FilesID'];
$sql_del = "delete from files where FilesID = '$del_FilesID';";
mysql_query($sql_del) or die(mysql_error());
}
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
?>
<style type="text/css">
<!--
a:link {
color: #0000FF;
text-decoration: none;
}
a:visited {
color: #0000FF;
text-decoration: none;
}
a:hover {
color: #0000FF;
text-decoration: none;
}
a:active {
color: #0000FF;
text-decoration: none;
}
body,td,th {
color: #000000;
}
body {
background-color: #99FFCC;
}
.style6 {color: #FF0000}
.style7 {
font-size: 18px;
font-weight: bold;
}
.style9 {color: #0000FF}
.style15 {color: #000000}
.style16 {font-size: 12px}
.style17 {font-size: 16px}
-->
-->login
-->
</style>
<table width="2542" height="100" border="1">
<tr>
<td width="200" height="100"><table width="228" border="1" style="width: 250
px">
<tbody>
<tr>
<td width="84"> Username</td>
<td width="128"><?php echo $objResult["Username"];?> <div align="center"></div></td>
</tr>
<tr>
<td height="23"> Name</td>
<td><?php echo $objResult["Name"];?></td>
</tr>
</tbody>
</table>
<a href="file:///C|/xampp/htdocs/edit_profile.php">Edit</a><br />
<a href="file:///C|/xampp/htdocs/logout.php">Logout</a></td>
<td width="2326"> </td>
</tr>
</table>
<table width="2542" height="55" border="1">
<tr>
<td width="265" height="49"><img src="file:///C|/xampp/htdocs/Img/A.jpg"width="275" height="45" /></td>
<td width="2261"><table width="597" border="1"cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<tr>
<th width="393" height="40" align="center" ><form id="form1" name="form1" method="post" action="show.php"><div align="center">search
<input name="txt_search" type="text" value="<?=$_POST['txt_search']?>" />
<input name="Search" type="submit" value="search" />
</div>
</form></th>
<th width="84" scope="col"><a href="add_form.php?edit_id=<?=$row_show[id]?>">Add data</a></th>
<th width="98" scope="col">
<!--#print Previwe -->
<script language="javascript">
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
<input name="btnPrint" type="button" id="btnPrint" value="Print" onClick="JavaScript:this.style.display='none';printpr();"></th>
</tr>
</table></td>
</tr>
</table>
<table width="2544" border="1">
<tr>
<th width="154" rowspan="2" valign="top" scope="col"> </th>
<th width="2374" align="left" valign="top" scope="col">
<?PHP
#ฟังก์ชั่นนี้ใช้สำหรับ Rename ชื่อไฟล์ที่ทำการอัพโหลดใหม่ รับค่า $_FILES['file']['name']
#ผลลัพธิ์จะได้ เช่น รับค่า ทดสอบ.docx ฟังก์ชั่นจะส่งค่ามาเป็น Acdeq12345678.docx เป็นต้น
function getNewName($fileName){
$fileName = explode('.',$fileName);
$i = count($fileName)-1;
$fileType = strtolower($fileName[$i]);
$rand = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),0,5);
$result = $rand.time().'.'.$fileType;
return $result;
}
$db = new mysqli("localhost", "root", "root", "mydatabase");
$db->set_charset("utf8");
/* check connection */
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
exit();
}
if(!empty($_POST['button'])){
$content_title = !empty($_POST['content_title']) ? $_POST['content_title'] : NULL;
$content_detail = !empty($_POST['content_detail']) ? $_POST['content_detail'] : NULL;
$description = !empty($_POST['description']) ? $_POST['description'] : NULL;
if(!empty($content_title)){
$db->query(" INSERT INTO tbl_content( content_name,content_detail,description ) VALUES( '$content_title', '$content_detail', '$description' ) "); #บันทึกลงฐานข้อมูล
$lastId = $db->insert_id; # ID ล่าสุดที่ทำการบันทึก และนำไปอ้างอิงในตารางที่เก็บไฟล์แนบ
if(!empty($lastId)){
for($i=1;$i<=5;$i++){
$file_title = $_POST['filename_'.$i];
$file_name = $_FILES['files_'.$i]['name'];
$file_tmp = $_FILES['files_'.$i]['tmp_name'];
$part = 'uploads/';
if( !empty($file_title) && !empty($file_name) ) {
$newFileName = getNewName($file_name);
if (move_uploaded_file($file_tmp, $part.$newFileName)) {
$db->query(" INSERT INTO tbl_files( ref_content_id, files_title, files_name ) VALUES( '$lastId', '$file_title', '$newFileName' ) "); #บันทึกลงฐานข้อมูล
}
}
} #End for()
echo 'Success';
} #End if(!empty($lastId))
} #End if(!empty($content_title))
} #End if(!empty($_POST['button']))
?>
<form enctype="multipart/form-data" method="post">
<table width="690" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="34" colspan="2" scope="row">Material master mapping</th>
</tr>
<tr>
<th height="31" colspan="2" align="left" scope="row"> Itemp :
<input type="text" name="content_title" id="content_title" size="44" /></th>
</tr>
<tr>
<tr>
<th height="31" colspan="2" align="left" scope="row"> Description :
<input type="text" name="description" id="description" size="44" /></th>
</tr>
<tr>
<th width="320" height="28" bgcolor="#FFFFCC" scope="row">ชื่อไฟล์</th>
<th width="370" bgcolor="#FFFFCC" scope="row">แนบไฟล์</th>
</tr>
<?PHP for($i=1;$i<=5;$i++){ ?>
<tr>
<th height="32" scope="row"><input name="filename_<?PHP echo $i; ?>" type="text" id="filename_<?PHP echo $i; ?>" size="50" /></th>
<th scope="row"><input type="file" name="files_<?PHP echo $i; ?>" id="files_<?PHP echo $i; ?>" /></th>
</tr>
<?PHP } ?>
<tr>
<th colspan="2" scope="row" height="45"><p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
<p> </p></th>
</tr>
</table>
</form>
<table width="902" border="1" cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<br>
<tr>
<td width="87"><div align="center" class="style6"> Itemp</div></td>
<td width="83"><div align="center" class="style6">Description</div></td>
<td width="146"><div align="center" class="style6">Picture1</div></td>
<td width="152"><div align="center" class="style6">Picture2</div></td>
<td width="83"><div align="center" class="style6">Picture3</div></td>
<td width="80"><div align="center" class="style6">Picture4</div></td>
<td width="88"><div align="center" class="style6">Picture5</div></td>
<td width="90"><div align="center" class="style6">delete</div></td>
<td width="213"><div align="center" class="style6">edit</div></td>
</tr>
<?php
$sql_show = "select * from tbl_content";
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
?>
<?php
$sql_show = "select * from tbl_content";
if($_POST['Search'])
{
$txt_search = $_POST['txt_search'];
$sql_show.=" where '%$txt_search%' or item like '%$txt_search%' or item like '%$txt_search%' or description like '%$txt_search%' or model like '%$txt_search%' ";
}
$result_show = mysql_query($sql_show) or die(mysql_error());
while($row_show = mysql_fetch_array($result_show))
{
?>
<tr>
<td><div align="center"><?=$row_show['content_name']?></div></td>
<td><div align="center"><?=$row_show['description']?></div></td>
<td><div align="center"><?=$row_show['files_name ']?></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"><a href="show.php?del_FilesID=<?=$row_show[FilesID]?>"onclick="return confirm('Are you sure you want to delete')">delete</a></div></td>
<td><div align="center"><a href="show.php?del_id=<?=$row_show[id]?>">edit</a></div></td
>
</tr>
<script language="JavaScript">
function Conf<? echo "$FilesID" ?>(object)
{
if (confirm("Do you want to delete [ <? echo " $FilesID " ?> ] ?") ==true)
{
return true;
}
return false;
}
</font>
</script>
<?php
}
?>
</table>
<br>
<table width="597" border="1"cellspacing="0" cellpadding="0"bgcolor="#FFFF99"bordercolor="#FF9900">
<tr>
<th width="393" height="40" align="center" >
</body>
</html>
ขอบคุณมากๆเลยนะครับ
|
 |
 |
 |
 |
Date :
2015-11-16 17:26:44 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาไปเล่นดู
Code (PHP)
<?php
class clsConnect{
public $table='';
public function __construct(){
$this->db=mysqli_init();
$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600);
$this->db->real_connect('localhost', 'root', 'root', 'test');
$this->db->set_charset('utf8');
}
public function SelectAll($table, $where=array(), $orderby='', $limit=''){
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
if(!empty($limit)){
$limit="LIMIT $limit";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
$limit
";
$result=array();
$query=$this->db->query($sql);
$result['num']=$query->num_rows;
while(($item=$query->fetch_assoc())){
$result['row'][]=$item;
}
return $result;
$result->free();
}
public function SelectOne($table, $where=array(), $orderby=''){
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
LIMIT 0,1
";
$result=array();
$query=$this->db->query($sql);
$result['row']=$query->fetch_assoc();
$result['num']=$query->num_rows;
return $result;
$result->free();
}
public function Insert($table='', $data=array()){
if(!empty($data)){
$attribute_arr=array();
$values_arr=array();
foreach($data as $fields=>$val){
$attribute_arr[]=$fields;
$values_arr[]="'".$this->db->real_escape_string($val)."'";
}
$attribute=implode(',', $attribute_arr);
$values=implode(',', $values_arr);
$sql="
INSERT INTO $table ($attribute)
VALUES($values);
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
$result['code']=$this->db->insert_id;
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Update($table='', $data=array(), $where=array()){
if(!empty($data)){
$attribute_arr=array();
$where_arr=array();
foreach($data as $fields=>$value){
$value=$this->db->real_escape_string($value);
$attribute_arr[]=" $fields = '$value' ";
}
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$attribute=implode(', ', $attribute_arr);
$whereqry=implode(' AND ', $where_arr);
$sql="
UPDATE $table SET
$attribute
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Delete($table='', $where=array()){
if(!empty($where)){
$where_arr=array();
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$whereqry=implode(' AND ', $where_arr);
$sql="
DELETE FROM
$table
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$this->error[]='NOT FOUND DATA';
}
return $result;
}
}
$db=new clsConnect();
$data = $db->SelectAll('tbl_content');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body class="container">
<div class="col-md-12 well">
<form id="form1" class="form-inline" name="form1" method="post" action="show.php"><div align="center">
<label>Search</label>
<input name="txt_search" type="text" class="form-control">
<input class="btn btn-primary" type="submit" value="search" />
</div>
</form>
</div>
<div class="col-md-12 form-horizontal">
<div class="form-title">Material master mapping</div>
<div class="form-group">
<label class="col-sm-2 control-label">Itemp</label>
<div class="col-sm-10">
<input type="text" name="content_title" id="content_title" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="text" name="description" id="description" class="form-control">
</div>
</div>
</div>
<div class="col-md-12">
<form enctype="multipart/form-data" method="post">
<table class="table">
<?PHP for($i=1; $i <= 5; $i++){?>
<tr>
<td height="32" scope="row"><input name="filename_<?PHP echo $i;?>" type="text" id="filename_<?PHP echo $i;?>" size="50" /></td>
<td scope="row"><input type="file" name="files_<?PHP echo $i;?>" id="files_<?PHP echo $i;?>" /></td>
</tr>
<?PHP }?>
<tr>
<td align="center" colspan="2">
<button class="btn btn-success">Submit</button>
</td>
</tr>
</table>
</form>
</div>
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th>Itemp</th>
<th>Description</th>
<th>Picture1</th>
<th>Picture2</th>
<th>Picture3</th>
<th>Picture4</th>
<th>Picture5</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach((array)$data['row'] as $i => $item){
$file = $db->SelectAll('tbl_files',array('content_id'=>$item['content_id']));
echo '<tr>';
echo '<td>'.$item['content_name'].'</td>';
echo '<td>'.$item['description'].'</td>';
foreach((array)$file['row'] as $n => $sub){
echo '<td>'.$sub['files_title'].'</td>';
}
echo '<td>delete</td>';
echo '<td>del</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
Code (SQL)
-- phpMyAdmin SQL Dump
-- version 3.1.3.1
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง:
-- รุ่นของเซิร์ฟเวอร์: 5.1.33
-- รุ่นของ PHP: 5.2.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `test`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `tbl_content`
--
CREATE TABLE IF NOT EXISTS `tbl_content` (
`content_id` int(5) NOT NULL AUTO_INCREMENT,
`content_name` varchar(255) NOT NULL,
`content_detail` text NOT NULL,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`content_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- dump ตาราง `tbl_content`
--
INSERT INTO `tbl_content` (`content_id`, `content_name`, `content_detail`, `description`) VALUES
(1, 'TEST1', '', 'TEST1'),
(2, 'TEST2', '', 'TEST2');
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `tbl_files`
--
CREATE TABLE IF NOT EXISTS `tbl_files` (
`files_id` int(10) NOT NULL AUTO_INCREMENT,
`content_id` int(11) NOT NULL DEFAULT '0',
`files_title` varchar(255) NOT NULL,
`files_name` varchar(25) NOT NULL,
PRIMARY KEY (`files_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
--
-- dump ตาราง `tbl_files`
--
INSERT INTO `tbl_files` (`files_id`, `content_id`, `files_title`, `files_name`) VALUES
(1, 1, 'sfsf', 'RJUxz1447487443.jpg'),
(2, 1, 'sss', 'kD2Ml1447487512.jpg'),
(3, 1, 'sss', 'TnN4v1447487589.jpg'),
(4, 1, 'ddd', 'mxHp91447487606.jpg'),
(5, 1, 'yty', 'Vj9Ly1447487628.jpg'),
(6, 2, 'rrr', 'VYocq1447487715.jpg'),
(7, 2, 'rrr', 'bDNjL1447487727.jpg'),
(8, 2, 'uuu', 'oSaBs1447487744.jpg'),
(9, 2, 'fsafaf', 'MVJle1447488084.jpg'),
(10, 2, 'dss', '8lute1447488157.jpg');
|
 |
 |
 |
 |
Date :
2015-11-16 17:58:48 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ ขอบคุณมากครับ
เดี่ยวมาบอกผลครับ
|
 |
 |
 |
 |
Date :
2015-11-16 18:01:54 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Notice: Undefined variable: qrywhere in C:\xampp\htdocs\barcode\show.php on line 33
Notice: Undefined variable: qrywhere in C:\xampp\htdocs\barcode\show.php on line 18
Notice: Undefined variable: qrywhere in C:\xampp\htdocs\barcode\show.php on line 18
ข้อมูลแสดงอยู่ครับ สร้างมาบันทึกใหม่ก็ไม่ได้ครับ หรือว่าให้ผมมาเพิ่มเอาครับ
|
ประวัติการแก้ไข 2015-11-16 18:30:10
 |
 |
 |
 |
Date :
2015-11-16 18:17:52 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เติม public $qrywhere = '';:
|
ประวัติการแก้ไข 2015-11-16 18:35:56
 |
 |
 |
 |
Date :
2015-11-16 18:34:46 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรงไหนครับ
|
 |
 |
 |
 |
Date :
2015-11-16 18:41:17 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
class clsConnect{
public $qrywhere = '';
public $table='';
ถูกมั้ยครับ
|
 |
 |
 |
 |
Date :
2015-11-16 18:47:25 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หาย error ไหมคับ ถูกละ พอดีผมปิดแสดง error เลยไม่เห็น
|
 |
 |
 |
 |
Date :
2015-11-16 19:02:21 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Notice: Undefined variable: qrywhere in C:\xampp\htdocs\barcode\show.php on line 22
Notice: Undefined variable: qrywhere in C:\xampp\htdocs\barcode\show.php on line 22
ออกไปตัวหนึงแล้วครับ เหลืออีก 2 ตัวครับ
|
 |
 |
 |
 |
Date :
2015-11-16 19:08:00 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
copy class ไปใหม่ฮะ
Code (PHP)
class clsConnect{
public $table='';
public function __construct(){
$this->db=mysqli_init();
$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600);
$this->db->real_connect('localhost', 'root', 'root', 'test');
$this->db->set_charset('utf8');
}
public function SelectAll($table, $where=array(), $orderby='', $limit=''){
$qrywhere = '';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
if(!empty($limit)){
$limit="LIMIT $limit";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
$limit
";
$result=array();
$query=$this->db->query($sql);
$result['num']=$query->num_rows;
while(($item=$query->fetch_assoc())){
$result['row'][]=$item;
}
return $result;
$result->free();
}
public function SelectOne($table, $where=array(), $orderby=''){
$qrywhere = '';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
LIMIT 0,1
";
$result=array();
$query=$this->db->query($sql);
$result['row']=$query->fetch_assoc();
$result['num']=$query->num_rows;
return $result;
$result->free();
}
public function Insert($table='', $data=array()){
if(!empty($data)){
$attribute_arr=array();
$values_arr=array();
foreach($data as $fields=>$val){
$attribute_arr[]=$fields;
$values_arr[]="'".$this->db->real_escape_string($val)."'";
}
$attribute=implode(',', $attribute_arr);
$values=implode(',', $values_arr);
$sql="
INSERT INTO $table ($attribute)
VALUES($values);
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
$result['code']=$this->db->insert_id;
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Update($table='', $data=array(), $where=array()){
if(!empty($data)){
$attribute_arr=array();
$where_arr=array();
foreach($data as $fields=>$value){
$value=$this->db->real_escape_string($value);
$attribute_arr[]=" $fields = '$value' ";
}
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$attribute=implode(', ', $attribute_arr);
$whereqry=implode(' AND ', $where_arr);
$sql="
UPDATE $table SET
$attribute
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Delete($table='', $where=array()){
if(!empty($where)){
$where_arr=array();
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$whereqry=implode(' AND ', $where_arr);
$sql="
DELETE FROM
$table
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$this->error[]='NOT FOUND DATA';
}
return $result;
}
}
|
 |
 |
 |
 |
Date :
2015-11-16 19:10:08 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ได้แล้วครับ
คราวนี้ในส่วนที่ต้องกรสร้างใหม่แล้ว บันทึกไม่ได้ นะครับ ตอ้งไปเพิ่มตรงไหนบ้างครับ
|
 |
 |
 |
 |
Date :
2015-11-16 19:15:42 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลัก 4 ทุ่มเด๋วมาใหม่ เล่น hon ก่อน
|
 |
 |
 |
 |
Date :
2015-11-16 19:19:08 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ครับ ขอบคุณนะครับ ที่ ช่วยเหลือมาโดยตลอดครับ
|
 |
 |
 |
 |
Date :
2015-11-16 19:22:35 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเทส insert ข้อมูลกับไฟล์ดูครับ ลง DB ไหม ยังไม่ได้ move file นะ เทสลง DB เฉยๆ
Code (PHP)
<?php
class clsConnect{
public $table='';
public function __construct(){
$this->db=mysqli_init();
$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600);
$this->db->real_connect('localhost', 'root', 'root', 'test');
$this->db->set_charset('utf8');
}
public function SelectAll($table, $where=array(), $orderby='', $limit=''){
$qrywhere = '';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
if(!empty($limit)){
$limit="LIMIT $limit";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
$limit
";
$result=array();
$query=$this->db->query($sql);
$result['num']=$query->num_rows;
while(($item=$query->fetch_assoc())){
$result['row'][]=$item;
}
return $result;
$result->free();
}
public function SelectOne($table, $where=array(), $orderby=''){
$qrywhere = '';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
LIMIT 0,1
";
$result=array();
$query=$this->db->query($sql);
$result['row']=$query->fetch_assoc();
$result['num']=$query->num_rows;
return $result;
$result->free();
}
public function Insert($table='', $data=array()){
if(!empty($data)){
$attribute_arr=array();
$values_arr=array();
foreach($data as $fields=>$val){
$attribute_arr[]=$fields;
$values_arr[]="'".$this->db->real_escape_string($val)."'";
}
$attribute=implode(',', $attribute_arr);
$values=implode(',', $values_arr);
$sql="
INSERT INTO $table ($attribute)
VALUES($values);
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
$result['code']=$this->db->insert_id;
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Update($table='', $data=array(), $where=array()){
if(!empty($data)){
$attribute_arr=array();
$where_arr=array();
foreach($data as $fields=>$value){
$value=$this->db->real_escape_string($value);
$attribute_arr[]=" $fields = '$value' ";
}
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$attribute=implode(', ', $attribute_arr);
$whereqry=implode(' AND ', $where_arr);
$sql="
UPDATE $table SET
$attribute
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Delete($table='', $where=array()){
if(!empty($where)){
$where_arr=array();
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$whereqry=implode(' AND ', $where_arr);
$sql="
DELETE FROM
$table
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$this->error[]='NOT FOUND DATA';
}
return $result;
}
}
$db=new clsConnect();
if(isset($_POST['submitform']){
$value = $_POST;
$filename = $_POST['files_title'];
unset($value['files_title']):
$file = $_FILE['files_name'];
$result = $db->Insert('tbl_content',$value);
foreach((array)$file as $i => $item){
$db->Insert('tbl_files',array('file_title'=>$filename[$i],'file_name'=>$file[$i]),array('content_id'=>$result['code']));
}
}
$data = $db->SelectAll('tbl_content');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body class="container">
<div class="col-md-12 well">
<div class="form-inline">
<label>Search</label>
<input name="txt_search" type="text" class="form-control">
<button class="btn btn-primary" type="button"/>Click Here</button>
</div>
</div>
<div class="col-md-12 form-horizontal">
<div class="form-title">Material master mapping</div>
<div class="form-group">
<label class="col-sm-2 control-label">Itemp</label>
<div class="col-sm-10">
<input type="text" name="content_title" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="text" name="description" class="form-control">
</div>
</div>
</div>
<div class="col-md-12">
<form enctype="multipart/form-data" method="post">
<table class="table">
<?PHP for($i=1; $i <= 5; $i++){?>
<tr>
<td height="32" scope="row"><input name="files_title[]" type="text"></td>
<td scope="row"><input type="file" name="files_name[]"></td>
</tr>
<?PHP }?>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="submitform">
<button class="btn btn-success" type="submit">Submit</button>
</td>
</tr>
</table>
</form>
</div>
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th>Itemp</th>
<th>Description</th>
<th>Picture1</th>
<th>Picture2</th>
<th>Picture3</th>
<th>Picture4</th>
<th>Picture5</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach((array)$data['row'] as $i => $item){
$file = $db->SelectAll('tbl_files',array('content_id'=>$item['content_id']));
echo '<tr>';
echo '<td>'.$item['content_name'].'</td>';
echo '<td>'.$item['description'].'</td>';
foreach((array)$file['row'] as $n => $sub){
echo '<td>'.$sub['files_title'].'</td>';
}
echo '<td>delete</td>';
echo '<td>del</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
|
ประวัติการแก้ไข 2015-11-16 20:42:50
 |
 |
 |
 |
Date :
2015-11-16 20:37:05 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Parse error: syntax error, unexpected '{' in C:\AppServ\www\barcode\show.php on line 184
รบกวนด้วยครับ
|
 |
 |
 |
 |
Date :
2015-11-16 23:05:53 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้อมูล ลง DB หมดละ
สิ่งที่คุณต้องไปทำต่อ
1. move_upload_file
2. ดักค่า อันไหนต้องการให้กรอก
3. ทำตัวเสิช
Code (PHP)
<?php
class clsConnect{
public $table='';
public function __construct(){
$this->db=mysqli_init();
$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600);
$this->db->real_connect('localhost', 'root', '', 'test');
$this->db->set_charset('utf8');
}
public function SelectAll($table, $where=array(), $orderby='', $limit=''){
$qrywhere='';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
if(!empty($limit)){
$limit="LIMIT $limit";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
$limit
";
$result=array();
$query=$this->db->query($sql);
while(($item=$query->fetch_assoc())){
$result[]=$item;
}
return $result;
$result->free();
}
public function SelectOne($table, $where=array(), $orderby=''){
$qrywhere='';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
LIMIT 0,1
";
$result=array();
$query=$this->db->query($sql);
$result=$query->fetch_assoc();
return $result;
$result->free();
}
public function Insert($table='', $data=array()){
if(!empty($data)){
$attribute_arr=array();
$values_arr=array();
foreach($data as $fields=>$val){
$attribute_arr[]=$fields;
$values_arr[]="'".$this->db->real_escape_string($val)."'";
}
$attribute=implode(',', $attribute_arr);
$values=implode(',', $values_arr);
$sql="
INSERT INTO $table ($attribute)
VALUES($values);
";
// echo $sql;
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
$result['code']=$this->db->insert_id;
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Update($table='', $data=array(), $where=array()){
if(!empty($data)){
$attribute_arr=array();
$where_arr=array();
foreach($data as $fields=>$value){
$value=$this->db->real_escape_string($value);
$attribute_arr[]=" $fields = '$value' ";
}
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$attribute=implode(', ', $attribute_arr);
$whereqry=implode(' AND ', $where_arr);
$sql="
UPDATE $table SET
$attribute
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Delete($table='', $where=array()){
if(!empty($where)){
$where_arr=array();
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$whereqry=implode(' AND ', $where_arr);
$sql="
DELETE FROM
$table
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$this->error[]='NOT FOUND DATA';
}
return $result;
}
}
$db=new clsConnect();
//var_dump($_POST);
if(!empty($_POST['submitform'])){
$value=$_POST;
$filename=$value['files_title'];
$file=$_FILES['files_name'];
unset($value['files_title']);
unset($value['submitform']);
$result=$db->Insert('tbl_content', $value);
foreach((array)$filename as $i=>$item){
// if(!$item)continue;
$db->Insert('tbl_files', array('files_title'=>$item, 'files_name'=>$file['name'][$i],'content_id'=>$result['code']));
}
}
$data=$db->SelectAll('tbl_content');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body class="container">
<div class="col-md-12 well">
<div class="form-inline">
<label>Search</label>
<input name="txt_search" type="text" class="form-control">
<button class="btn btn-primary" type="button"/>Click Here</button>
</div>
</div>
<form enctype="multipart/form-data" method="post">
<div class="col-md-12 form-horizontal">
<div class="form-title">Material master mapping</div>
<div class="form-group">
<label class="col-sm-2 control-label">Itemp</label>
<div class="col-sm-10">
<input type="text" name="content_name" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="text" name="description" class="form-control">
</div>
</div>
</div>
<div class="col-md-12">
<table class="table">
<?PHP for($i=1; $i <= 5; $i++){?>
<tr>
<td height="32" scope="row"><input name="files_title[]" type="text"></td>
<td scope="row"><input type="file" name="files_name[]"></td>
</tr>
<?PHP }?>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="submitform" value="submit">
<button class="btn btn-success" type="submit">Submit</button>
</td>
</tr>
</table>
</div>
</form>
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th>Itemp</th>
<th>Description</th>
<th>Picture1</th>
<th>Picture2</th>
<th>Picture3</th>
<th>Picture4</th>
<th>Picture5</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach((array)$data as $i=>$item){
$files=$db->SelectAll('tbl_files', array('content_id'=>$item['content_id']));
echo '<tr>';
echo '<td>'.$item['content_name'].'</td>';
echo '<td>'.$item['description'].'</td>';
foreach((array)$files as $n=>$sub){
echo '<td>'.$sub['files_title'].'</td>';
}
echo '<td>delete</td>';
echo '<td>del</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
|
ประวัติการแก้ไข 2015-11-16 23:55:58
 |
 |
 |
 |
Date :
2015-11-16 23:44:47 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ครับ ขอบคุณครับ แล้วถ้ามีอะไรผมจะมาขอคำตอบใหม่นะครับ
|
 |
 |
 |
 |
Date :
2015-11-17 08:00:14 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ระหว่าง MOVE กับ Copy ควรจะใช้แบบไหนดีครับ
|
 |
 |
 |
 |
Date :
2015-11-17 08:38:38 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
move
|
 |
 |
 |
 |
Date :
2015-11-17 09:29:49 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้า code แบบนี้พอมั้ยครับสำหรับ MoVE อันนี้ของเก่าที่ผมเขียนไว้นะครับ มาเจอ Code ใหม่ก็งง อยู่ครับ
{
$file_title = $_POST['filename_'.$i];
$file_name = $_FILES['files_'.$i]['name'];
$file_tmp = $_FILES['files_'.$i]['tmp_name'];
$part = 'uploads/'; ////... ส่วนนี้ต้องสร้างใหม่มั้ยครับ
if( !empty($file_title) && !empty($file_name) ) {
$newFileName = getNewName($file_name);
if (move_uploaded_file($file_tmp, $part.$newFileName)) {
$db->query(" INSERT INTO tbl_files( ref_content_id, files_title, files_name ) VALUES( '$lastId', '$file_title', '$newFileName' ) "); #บันทึกลงฐานข้อมูล
}
|
 |
 |
 |
 |
Date :
2015-11-17 09:42:37 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อะคับ เพิ่ม upload ให้ละ
เอาไปแล้วลองศึกษาดูด้วยนะคับ ><
สงสัยตรงไหนใน code ถามได้ฮะ
ไม่อยากให้แค่เอาไปใช้เฉยๆ ไม่งั้นก็ไม่รู้ว่าทำไมถึงเขียนแบบนี้
อาจจะเขียนตามแนวทางของตัวเอง ก็อยากให้เขียน เป็น รูปแบบนิดนึง จัดกลุ่มของ โครงสร้าง ไม่ควร เอาไปแทรกๆๆ ระหว่าง code
Code (PHP)
<?php
class clsConnect{
public $table='';
public function __construct(){
$this->db=mysqli_init();
$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3600);
$this->db->real_connect('localhost', 'root', 'root', 'test');
$this->db->set_charset('utf8');
}
public function SelectAll($table, $where=array(), $orderby='', $limit=''){
$qrywhere='';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
if(!empty($limit)){
$limit="LIMIT $limit";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
$limit
";
$result=array();
$query=$this->db->query($sql);
while(($item=$query->fetch_assoc())){
$result[]=$item;
}
return $result;
$result->free();
}
public function SelectOne($table, $where=array(), $orderby=''){
$qrywhere='';
if(!empty($where)){
foreach((array)$where as $i=>$item){
$item=$this->db->real_escape_string($item);
$qrywhere .= "$i = '$item' AND ";
}
}
if(!empty($orderby)){
$orderby="ORDER BY $orderby";
}
$sql="
SELECT *
FROM $table
WHERE
$qrywhere
1
$orderby
LIMIT 0,1
";
$result=array();
$query=$this->db->query($sql);
$result=$query->fetch_assoc();
return $result;
$result->free();
}
public function Insert($table='', $data=array()){
if(!empty($data)){
$attribute_arr=array();
$values_arr=array();
foreach($data as $fields=>$val){
$attribute_arr[]=$fields;
$values_arr[]="'".$this->db->real_escape_string($val)."'";
}
$attribute=implode(',', $attribute_arr);
$values=implode(',', $values_arr);
$sql="
INSERT INTO $table ($attribute)
VALUES($values);
";
// echo $sql;
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
$result['code']=$this->db->insert_id;
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Update($table='', $data=array(), $where=array()){
if(!empty($data)){
$attribute_arr=array();
$where_arr=array();
foreach($data as $fields=>$value){
$value=$this->db->real_escape_string($value);
$attribute_arr[]=" $fields = '$value' ";
}
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$attribute=implode(', ', $attribute_arr);
$whereqry=implode(' AND ', $where_arr);
$sql="
UPDATE $table SET
$attribute
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$result['error']='NOT FOUND DATA';
}
return $result;
}
public function Delete($table='', $where=array()){
if(!empty($where)){
$where_arr=array();
foreach($where as $fields=>$value){
$value=$this->db->real_escape_string($value);
$where_arr[]=" $fields = '$value' ";
}
$whereqry=implode(' AND ', $where_arr);
$sql="
DELETE FROM
$table
WHERE
$whereqry
";
$query=$this->db->query($sql);
if($query){
$result['success']='OK';
}else{
$result['success']='FAIL';
$result['error']=$this->db->error;
}
}else{
$result['success']='FAIL';
$this->error[]='NOT FOUND DATA';
}
return $result;
}
}
$db=new clsConnect();
//var_dump($_POST);
if(!empty($_POST['submitform'])){
$value=$_POST;
$filename=$value['files_title'];
$file=$_FILES['files_name'];
unset($value['files_title']);
unset($value['submitform']);
$uploads_dir='upload';
foreach($file["error"] as $key=>$error){
if($error == UPLOAD_ERR_OK){
$tmp_name=$file["tmp_name"][$key];
$name=$file["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
$result=$db->Insert('tbl_content', $value);
foreach((array)$filename as $i=>$item){
// if(!$item)continue;
$db->Insert('tbl_files', array('files_title'=>$item, 'files_name'=>$file['name'][$i],'content_id'=>$result['code']));
}
}
$data=$db->SelectAll('tbl_content');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body class="container">
<div class="col-md-12 well">
<div class="form-inline">
<label>Search</label>
<input name="txt_search" type="text" class="form-control">
<button class="btn btn-primary" type="button"/>Click Here</button>
</div>
</div>
<form enctype="multipart/form-data" method="post">
<div class="col-md-12 form-horizontal">
<div class="form-title">Material master mapping</div>
<div class="form-group">
<label class="col-sm-2 control-label">Itemp</label>
<div class="col-sm-10">
<input type="text" name="content_name" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="text" name="description" class="form-control">
</div>
</div>
</div>
<div class="col-md-12">
<table class="table">
<?php for($i=1; $i <= 5; $i++){?>
<tr>
<td height="32" scope="row"><input name="files_title[]" type="text"></td>
<td scope="row"><input type="file" name="files_name[]"></td>
</tr>
<?php }?>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="submitform" value="submit">
<button class="btn btn-success" type="submit">Submit</button>
</td>
</tr>
</table>
</div>
</form>
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th>Itemp</th>
<th>Description</th>
<th>Picture1</th>
<th>Picture2</th>
<th>Picture3</th>
<th>Picture4</th>
<th>Picture5</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach((array)$data as $i=>$item){
$files=$db->SelectAll('tbl_files', array('content_id'=>$item['content_id']));
echo '<tr>';
echo '<td>'.$item['content_name'].'</td>';
echo '<td>'.$item['description'].'</td>';
foreach((array)$files as $n=>$sub){
echo '<td>'.$sub['files_title'].'</td>';
}
echo '<td>delete</td>';
echo '<td>del</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>
|
ประวัติการแก้ไข 2015-11-17 11:23:07
 |
 |
 |
 |
Date :
2015-11-17 11:20:16 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อครับ เดี่ยวผมค่อยๆศึกษา Code ตัวนี้ดูก่อนครับ อันนี้เป็นแยบใหม่ใช่มั้ยครับ
|
 |
 |
 |
 |
Date :
2015-11-17 11:45:32 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ok เรียบร้อยครับ เดี่ยวผมจะต่อยอดลงมาอีกครับ เดี่ยวลองทำดูก่อนครับ ผมจะเอาสิ่งที่ Add ลงมาใหม่ทำการสร้างฟอร์มเพื่อทำเงี่ยนไขในการคำนวณเดี่ยวผมลองดูก่อนครับ ถ้าติดตรงไหนเดี่ยวผมมาถามใหม่นะครับ แต่ต้องขอบคุณมากๆเลยครับ เดียวให่เสร็จ ทั้งหมดก่อนนะครับ เดี่ยวมีน้ำใจเล็กๆน้อยที่ช่วยใช้ความคิดให้นะครับ
|
 |
 |
 |
 |
Date :
2015-11-17 11:55:28 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนอีกแล้วครับ ลองทำดูแล้วเอา โค๊ดตระกร้าสินค้ามาดัดดูแล้วไม่สำเร็จ
ประมาณนี้โค๊ดประมาณไหนหรอครับ
อยากให้เลือก Inser แล้วไปอยู่ที่ Detail แต่ละรายการแบบตระกร้าสินค้านะครับ พอเลือก Detail มีรายการที่เรา Inser มาครับว่ามีอะไรบ้าง แล้วบันทึก ก็จะมีรายการที่ เรา inser มาเก็บไว้เพื่อนำมาเป็น DB ไปทำเงื่อนไขต่อไปนะครับ
|
 |
 |
 |
 |
Date :
2015-11-17 14:30:19 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งง คำถาม
|
 |
 |
 |
 |
Date :
2015-11-17 16:57:48 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวพรุ่งนี้มาถามใหม่ครับ ผมอยากได้ข้อมูลที่เราทำมาใช่มั้ยครับ เอาข้างหลังสุดมา เลือกนะครับ เลือกเท่าไรก็ได้ครับ แล้วบันทึกจะได้ 1 ใบ คล้ายๆกับเลือกสินค้านะครับ แล้วเก็บข้อมูลไว้ครับเป็นใบใหม่
|
 |
 |
 |
 |
Date :
2015-11-17 17:01:39 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะทำระบบตะกร้าสินค้า ?
คุณต้องไปศึกษาพวก cookie ไม่ก็ session มาด้วย ไม่งั้นก็ทำไม่ได้หรอก
|
 |
 |
 |
 |
Date :
2015-11-17 17:04:29 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวผมลองเทสทำดูก่อนนะครับ ถ้าติดตรงไหนเดี่ยวผมขออนุญาติถามนะครับ
|
 |
 |
 |
 |
Date :
2015-11-17 19:53:14 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองทำตระกร้าสินค้าดูแล้วครับ ใช้ได้อยู่ แต่ผมจะทำหน้าตรวจโดยการ ค้าหาจากชื่อลูกค้าครับ แล้วให้โปรแกรม ใส่ของตามจำนวณที่ลูกค้าสั่งนะครับ เพื่อ ยืนยันพนักงานด้วยครับว่าใส่ของตรงตามจำนวณรึเปล่า ถ้าไม่ตรงโปรแกรมจะไม่สามารถบันทึกได้นะครับ ควารทำโค๊ตประมาณไหนดีครับ
อันนี้โค๊ดหน้า แรกครับ
<?php
session_start();
require 'connect.php';
$meSql = "SELECT * FROM products ";
$meQuery = mysql_query($meSql);
$action = isset($_GET['a']) ? $_GET['a'] : "";
$itemCount = isset($_SESSION['cart']) ? count($_SESSION['cart']) : 0;
if(isset($_SESSION['qty'])){
$meQty = 0;
foreach($_SESSION['qty'] as $meItem){
$meQty = $meQty + $meItem;
}
}else{
$meQty=0;
}
?>
<!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>pissanu pongouvon Test</title>
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/nava.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">pissanu pongoubon Test</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.php">หน้าหลัก</a></li>
<li><a href="cart.php">Detail
<span class="badge"><?php echo $meQty; ?></span></a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div>
<!-- Main component for a primary marketing message or call to action --><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<tbody>
<h3>Select from item master</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Picture</th>
<th>Item</th>
<th>Description</th>
<th>box</th>
<th>Picture1</th>
<th>Picture2</th>
<th>Picture3</th>
<th>Picture4</th>
<th>Picture5</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php
while ($meResult = mysql_fetch_assoc($meQuery))
{
?>
<tr>
<td><img src="images/<?php echo $meResult['product_img_name1']; ?>" border="0"></td>
<td><?php echo $meResult['product_code']; ?></td>
<td><?php echo $meResult['product_name']; ?></td>
<td><?php echo $meResult['product_desc']; ?></td>
<td><?php echo $meResult['product_img_name']; ?></td>
<td><?php echo number_format($meResult['product_price'],2); ?></td>
<td><?php echo number_format($meResult['product_price'],2); ?></td>
<td><?php echo number_format($meResult['product_price'],2); ?></td>
<td><?php echo number_format($meResult['product_price'],2); ?></td>
<td>
<a class="btn btn-primary btn-lg" href="updatecart.php?itemId=<?php echo $meResult['id']; ?>" role="button">
<span class="glyphicon glyphicon-shopping-cart"></span>
เลือกข้อมูล</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- /container -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="bootstrap/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<?php
mysql_close();
|
 |
 |
 |
 |
Date :
2015-11-18 09:41:37 |
By :
pissanu8970 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|