รบกวนช่วยหน่อยค่ะคือหนูอยากจะ ดึงข้อมูลจาก 4 ตารางเพื่อที่จะค้นหาข้อมูลค่ะ
รบกวนขอตัวอย่างโค้ดหน่อยค่ะ
Code (PHP)
CREATE TABLE `cus_A` ( `Id` int(11) NOT NULL auto_increment, `Company` varchar(50) NOT NULL, `Code` varchar(6) NOT NULL, `Name_save` varchar(50) NOT NULL, `Name_pro` varchar(50) NOT NULL, `Piece` int(11) NOT NULL, `Status` varchar(10) NOT NULL, `Date` date NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; -- -- dump ตาราง `cus` -- INSERT INTO `cus` VALUES (1, 'A', '600001', 'MMM', 'box 30*30', 20, '2', '2018-01-01'); INSERT INTO `cus` VALUES (2, 'B', '600002', 'MMM', 'box 30*30', 10, '3', '2018-01-01'); INSERT INTO `cus` VALUES (3, 'C', '600003', 'PPP', 'box 60*60', 30, '3', '2018-01-01'); INSERT INTO `cus` VALUES (4, 'D', '600004', 'PPP', 'box 60*60', 20, '4', '2018-01-02'); INSERT INTO `cus` VALUES (5, 'E', '600005', 'WWW', 'box 20*20', 15, '4', '2018
CREATE TABLE `cus_B` ( `Id` int(11) NOT NULL auto_increment, `Company` varchar(50) NOT NULL, `Code` varchar(6) NOT NULL, `Name_save` varchar(50) NOT NULL, `Name_pro` varchar(50) NOT NULL, `Piece` int(11) NOT NULL, `Status` varchar(10) NOT NULL, `Date` date NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; -- -- dump ตาราง `cus` -- INSERT INTO `cus` VALUES (1, 'A', '600001', 'MMM', 'box 30*30', 20, '2', '2018-01-01'); INSERT INTO `cus` VALUES (2, 'B', '600002', 'MMM', 'box 30*30', 10, '3', '2018-01-01'); INSERT INTO `cus` VALUES (3, 'C', '600003', 'PPP', 'box 60*60', 30, '3', '2018-01-01'); INSERT INTO `cus` VALUES (4, 'D', '600004', 'PPP', 'box 60*60', 20, '4', '2018-01-02'); INSERT INTO `cus` VALUES (5, 'E', '600005', 'WWW', 'box 20*20', 15, '4', '2018
CREATE TABLE `cus_C` ( `Id` int(11) NOT NULL auto_increment, `Company` varchar(50) NOT NULL, `Code` varchar(6) NOT NULL, `Name_save` varchar(50) NOT NULL, `Name_pro` varchar(50) NOT NULL, `Piece` int(11) NOT NULL, `Status` varchar(10) NOT NULL, `Date` date NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; -- -- dump ตาราง `cus` -- INSERT INTO `cus` VALUES (1, 'A', '600001', 'MMM', 'box 30*30', 20, '2', '2018-01-01'); INSERT INTO `cus` VALUES (2, 'B', '600002', 'MMM', 'box 30*30', 10, '3', '2018-01-01'); INSERT INTO `cus` VALUES (3, 'C', '600003', 'PPP', 'box 60*60', 30, '3', '2018-01-01'); INSERT INTO `cus` VALUES (4, 'D', '600004', 'PPP', 'box 60*60', 20, '4', '2018-01-02'); INSERT INTO `cus` VALUES (5, 'E', '600005', 'WWW', 'box 20*20', 15, '4', '2018
CREATE TABLE `cus_D` ( `Id` int(11) NOT NULL auto_increment, `Company` varchar(50) NOT NULL, `Code` varchar(6) NOT NULL, `Name_save` varchar(50) NOT NULL, `Name_pro` varchar(50) NOT NULL, `Piece` int(11) NOT NULL, `Status` varchar(10) NOT NULL, `Date` date NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; -- -- dump ตาราง `cus` -- INSERT INTO `cus` VALUES (1, 'A', '600001', 'MMM', 'box 30*30', 20, '2', '2018-01-01'); INSERT INTO `cus` VALUES (2, 'B', '600002', 'MMM', 'box 30*30', 10, '3', '2018-01-01'); INSERT INTO `cus` VALUES (3, 'C', '600003', 'PPP', 'box 60*60', 30, '3', '2018-01-01'); INSERT INTO `cus` VALUES (4, 'D', '600004', 'PPP', 'box 60*60', 20, '4', '2018-01-02'); INSERT INTO `cus` VALUES (5, 'E', '600005', 'WWW', 'box 20*20', 15, '4', '2018
Tag : PHP, MySQL
ประวัติการแก้ไข 2018-01-20 14:29:38
Date :
2018-01-20 14:26:41
By :
panthipa
View :
706
Reply :
3
Code (PHP)
<?php if($_GET["txtKeyword"] != "" or $_GET["txtKeyword2"] != "" or $_GET["txtKeyword3"] != "") {
$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database"); $objDB = mysql_select_db("customer");
$strSQL = "SELECT * FROM cus_A UNION ALL
SELECT * FROM cus_B UNION ALL
SELECT * FROM cus_C UNION ALL
SELECT * FROM cus_D WHERE (Date between '".$_GET["txtKeyword"]."' and '".$_GET["txtKeyword2"]."' and Company LIKE '%".$_GET["txtKeyword3"]."%')"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?>
Date :
2018-01-21 06:04:44
By :
panthipa
Code (PHP)
if($_GET["txtKeyword"] != "" or $_GET["txtKeyword2"] != "" or $_GET["txtKeyword3"] != "") {
$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
$strSQL = "SELECT * FROM cus_A AS A
JOIN cus_B AS B ON(B.id = A.id_B)
JOIN cus_C AS C ON(C.id = B.id_C)
JOIN cus_D AS D ON(D.id = C.id_d)
WHERE (Date between '".$_GET["txtKeyword"]."' and '".$_GET["txtKeyword2"]."' and Company LIKE '%".$_GET["txtKeyword3"]."%')"
ลองศึกษา เกี่ยวกับการเชื่อมตารางด้วยกัน 3 ตารางด้วยนะครับ
https://www.thaicreate.com/tutorial/sql-join.html
Date :
2018-01-21 10:38:17
By :
menphurk
ไม่ได้ค่ะพี่มันยังแสดงข้อมูลแค่ตารางเดียว ทั้ง 4 table นี้เก็บค่าเหมือนกันทุกอย่างนะค่ะ
Date :
2018-01-24 15:41:37
By :
panthipa
Load balance : Server 01