|
 |
|
PHP ผมจะ SELECT 2 ตาราง ผมขอคำแนะนำหน่อยครับ ................. |
|
 |
|
|
 |
 |
|
ขอดูโครงสร้าง DB ของทั้งสองตารางหน่อยค่ะ
|
 |
 |
 |
 |
Date :
2012-08-08 11:55:52 |
By :
LuckyStar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฟิลด์ชื่อ UserID ของทั้งสองตารางเก็บค่าเดียวกันรึป่าวครับ (คือมีความสัมพันธ์กันรึป่าว หรือเป็น FK รึป่าว) ถ้าใช่ ก็ใช้ JOIN กันได้เลยครับ
SQL JOIN
SQL LEFT JOIN
|
 |
 |
 |
 |
Date :
2012-08-08 13:56:27 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$sql = "SELECT * FROM files INNER JOIN member ON (files .UserID=member.UserID) WHERE filesID = 'ตัวนี้ก็ส่วนที่ต้องการเปรียบเทียบ' ";
น่าจะประมาณนี้ครับ :)
|
 |
 |
 |
 |
Date :
2012-08-08 14:33:15 |
By :
mytree |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$strSQL = "SELECT member.*,files.* FROM member,files WHERE member.UserID = files.UserID";
มัน ไม่ได้อะครับ เพราะถ้า join แบบนั้น ค่าทุกค่าจะมารวมเป็น table เดียวกันหมด
ซึ่งผมมี 2 ฟอร์ม
ฟอร์ม 1 แสดง
- ชื่อ user อัพไฟล์
- ชื่อไฟล์
- วันเวลา อื่นๆ
ฟอร์ม 2 แสดง
- ชื่อ user ที่จะแก้ไข ชึ่งตามในรูปด้านบน ผม login คนละไอดีกันแล้ว แต่มันก้ยังแสดงเป็นชื่อของ ผู้ อัพไฟล์
พอมีวิธีอื่นมั้ยครับ หรือว่า ไม่ต้อง join เลย แยก เป็น แบบ นี้
Code (PHP)
mysql_connect("localhost","root","6845");
mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$objConnect = mysql_connect("localhost","root","6845") or die("Error Connect to Database");
$objDB = mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM files WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
|
 |
 |
 |
 |
Date :
2012-08-08 14:34:26 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Login ด้วย Bot1
แล้วอัพไฟล์

Logout Bot1
แล้ว Loginด้วย Bot 2 เพื่อไปแก้ไข ไฟล์ที่ Bot 1 อัพไว้

แต่ชื่อ ใน ช่องผู้ อัพไฟล์ ก้ยังขึ้นเป็น Bot 1 =="

|
 |
 |
 |
 |
Date :
2012-08-08 14:49:23 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
UploadFiles
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}
mysql_connect("localhost","root","6845");
mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style_uploadfile.css" type="text/css" />
<title>123</title>
</head>
<form action="Save_Upload.php" method="post" name="formupload" enctype="multipart/form-data">
<table width="100%" align="center" cellpadding="0" cellspacing="3" class="table">
<tr>
<td colspan="4" class="tb1" style="white-space:normal"><strong><img src="images/formupload.png" align="absmiddle"/> Form Uploadfile</strong></td>
</tr>
<tr>
<td class="tbl1" style="white-space: nowrap;"><div align="right"><strong>วันที่อัพไฟล์</strong></div></td>
<td colspan="1" valign="top" class="tbl1" style="white-space: nowrap;"><input name="dservice" type="text" class="idle" id="dservice" autocomplete="off" readonly="true"value="<? $date = date("d-m-y");$time = date("H-i-s");print $date;?>"/>
</td>
</tr>
<tr>
<td valign="top" class="tbl1" style="white-space: nowrap;"><div align="right"><strong>ชื่อผู้อัพไฟล์</strong></div></td>
<td colspan="3" valign="top" class="tbl1" style="white-space: nowrap;"><input name="Name_M" type="text" class="idle" id="Name_M" autocomplete="off" readonly="true" value="<?=$objResult["Name_M"];?>"/>
<div style="display:none;"> <input name="UserID" type="text" class="idle" id="UserID" autocomplete="off" readonly="true" value="<?=$objResult["UserID"];?>"/> </div>
</td>
</tr>
<tr>
<td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>ชื่อไฟล์</strong></div></td>
<td colspan="3" valign="top" class="tbl1" style="white-space:nowrap;"><input name="txtName" type="text" class="idle" id="Name_U" value=""/></td>
</tr>
<tr>
<td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>รายละเอียด</strong></div></td>
<td colspan="3" valign="top" class="tbl1" style="white-space:nowrap;"><textarea name="details" class="idle" id="Details" cols="45" rows="5"></textarea></td>
</tr>
<td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>ไฟล์ที่จะอัพ</strong></div></td>
<td colspan="3" valign="tbl1" class="tbl1" style="white-space:nowrap;"><input name="fileUpload" type="file" class="idle" id="FilesName" value="" /></td>
</tr>
<tr>
<td valign="top" class="tbl1" style="white-space: nowrap;"> </td>
<td colspan="3" valign="top" class="tbl1" style="white-space: nowrap;"><button type="submit" name="button" id="button" ><img src="images/save.png" alt="" width="16" height="16" align="absmiddle" /> บันทึก </button></td></tr>
</table>
</form>
Save_Upload.php
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}
ob_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style_uploadfile.css" type="text/css" />
<title>123</title>
</head>
<br>
<body>
<style type="text/css">
* {
margin:0;
padding:0;
font:"Times New Roman", Times, serif;
}
#wrapper{
width:420px;
margin: 200 auto;
padding:20px 20px 20px 20px;
border:20px solid #FF8000;
}
.box1 {
width:430px;
background: url(images/tile2.gif) repeat-y;
position:relative;
}
.box1:before {
content: url(images/top2.gif);
display:block;
}
.box1:after {
content: url(images/bottom2.gif);
display:block;
}
.txt{
padding: 0 10px;
}
</style>
<div id="wrapper">
<div class = "box1">
<p class="txt">
<?
if ((($_FILES["fileUpload"]["type"] == "image/gif")
|| ($_FILES["fileUpload"]["type"] == "image/jpeg")
|| ($_FILES["fileUpload"]["type"] == "image/pjpeg"))
&& ($_FILES["fileUpload"]["size"] < 1000000))
{
if ($_FILES["fileUpload"]["error"] > 0)
{
echo "Error: " . $_FILES["fileUpload"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["fileUpload"]["name"] . "<br />";
echo "Type: " . $_FILES["fileUpload"]["type"] . "<br />";
echo "Size: " . ($_FILES["fileUpload"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["fileUpload"]["tmp_name"];
}
if(move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"myfile/".$_FILES["fileUpload"]["name"]))
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","6845") or die("Error Connect to Database");
$objDB = mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$Date =date("d/m/y");
$Time =date("H:i:s");
$strSQL = "INSERT INTO files ";
$strSQL .="(UserID,Name,Date,Time,FilesName,Details,Name_M) VALUES ('".$_POST["UserID"]."','".$_POST["txtName"]."','$Date','$Time','".$_FILES["fileUpload"]["name"]."','".$_POST["details"]."','".$_POST["Name_M"]."')";
$objQuery = mysql_query($strSQL);
} else {//ถ้าไฟล์ที่อัพไม่เป็นไฟล์รูป หรือขนาดไฟล์เกิน 1000000
echo "ไฟล์ผิดประเภทหรือมีขนาดใหญ่เกินไป";
}
?>
<a href="index.php?page=ViewFiles"> View files</a>
</p>
</div>
</div>
|
 |
 |
 |
 |
Date :
2012-08-08 14:57:19 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
EditFiles
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}
?>
<html>
<head>
<title>Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","6845") or die("Error Connect to Database");
$objDB = mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT member.*,files.* FROM member,files WHERE member.UserID = files.UserID";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
?>
<form name="form1" method="post" action="Save_Editfiles.php?FilesID=<?=$_GET["FilesID"];?>" enctype="multipart/form-data">
<p>Edit Picture :<br>
Name : <input type="text" name="txtName" value="<?=$objResult["Name"];?>">
<br>
<input name="dservice" type="text" class="idle" id="dservice" autocomplete="off" readonly="true"value="<? $date = date("d-m-y");$time = date("H-i-s");print $date;?>"/><br>
<input name="Name_M" type="text" class="idle" id="Name_M" autocomplete="off" readonly="true" value="<?=$objResult["Name_M"];?>"/>
<input name="UserID" type="text" class="idle" id="UserID" autocomplete="off" readonly="true" value="<?=$objResult["UserID"];?>"/>
Picture : <input type="file" name="fileUpload"><br>
<input type="hidden" name="hdnOldFile" value="<?=$objResult["FilesName"];?>">
<input name="btnSubmit" type="submit" value="Submit">
</p>
<p><img width="250" height="250" src="myfile/<?=$objResult["Filesname"];?>"></p>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-08-08 14:58:22 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ตอนอัพโหลด
ผมดึงพวก
id user
name user
และ ตั้ง วัน เวลา ไว้
พอจะอัพ
จากฐานข้อมูลมา
และพอผมจะอัพผมก้ส่งค่า พวกนี้ ไปที่ Table files
แล้วพอจะดู ข้อมูลของไฟล์ที่ อัพขึ้นไปว่า
user ไหนอัพ
วัน เวลา อะไร
ผมก้จะดึงข้อมูลจาก Table files มาแสดงอีกรอบนึ่ง
เพราะ ผมทำแบบนี้หรือเปล่า เลยมีปัญหา แสดงข้อมูลตอน Edit files อะครับ เพราะผมไม่ได้ join ตั้งแต่ตอนแรก
ผมก้ออกแบบระบบไม่เก่งด้วย T_T ทำได้ที่ผ่านๆมา ก้ ทำแบบตรงๆ ไม่ค่อยได้ประยุกต์อะไรเลย
|
 |
 |
 |
 |
Date :
2012-08-08 15:02:47 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|