$strSQL = "select A.Model_Name,B.Car,C.Brand_Name from model A left join brand B on (A.ID_Brand = A.ID_Brand) left join car C on (A.ID_Car) = C.ID_Car ";
$strSQL = "
SELECT A.Model_Name,B.Car,C.Brand_Name
FROM model A
LEFT JOIN brand B on (A.ID_Brand = B.ID_Brand)
LEFT JOIN car C on (A.ID_Car = C.ID_Car )";
$strSQL = "
SELECT A.Model_Name,B.Brand_Name,C.Car
FROM model A
LEFT JOIN brand B on (A.ID_Brand = B.ID_Brand)
LEFT JOIN car C on (A.ID_Car = C.ID_Car)";
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\KPS\admin\model.php on line 315
อ่ค่ะ
<?
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mysql_select_db("vehicles");
$cs1 = "SET character_set_results=tis620";
mysql_query($cs1) or die('Error query: ' . mysql_error());
$cs2 = "SET character_set_client = tis620";
mysql_query($cs2) or die('Error query: ' . mysql_error());
$cs3 = "SET character_set_connection = tis620";
mysql_query($cs3) or die('Error query: ' . mysql_error());
//$strSQL = "SELECT * FROM model";
$strSQL = "
SELECT A.Model_Name,B.Brand_Name,C.Car
FROM model A
LEFT JOIN brand B on (A.ID_Brand = B.ID_Brand)
LEFT JOIN car C on (A.ID_Car = C.ID_Car)";
//$strSQL="SELECT A.Dep_Name,B.Nm_Fac FROM department A LEFT JOIN faculty B ON(A.ID_Fac=B.ID_Fac)";
//$strSQL = "select A.Model_Name,B.Car,C.Brand_Name from model A left join brand B on (A.ID_Brand = A.ID_Brand) left join car C on (A.ID_Car) = C.ID_Car ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
<?
$strSQL = "
SELECT A.Model_Name,B.Brand_Name,C.Car
FROM model A
LEFT JOIN brand B on (A.ID_Brand = B.ID_Brand)
LEFT JOIN car C on (A.ID_Car = C.ID_Car)";
//$strSQL="SELECT A.Dep_Name,B.Nm_Fac FROM department A LEFT JOIN faculty B ON(A.ID_Fac=B.ID_Fac)";
//$strSQL = "select A.Model_Name,B.Car,C.Brand_Name from model A left join brand B on (A.ID_Brand = A.ID_Brand) left join car C on (A.ID_Car) = C.ID_Car ";
?>
<?
$strSQL = "SELECT A.Model_Name,B.Brand_Name,C.Car";
$strSQL.="FROM model A LEFT JOIN brand B ON(A.ID_Brand=B.ID_Brand)";
$strSQL.="LEFT JOIN car C ON(A.ID_Car=C.ID_Car)";
?>
ถ้าต้องการ Show Data ที่ table Model เป็นหลักลองใช้แบบนี้ดูครับ
Code
select A.Model_Name,isnull(B.Car,'') as Car,isnull(C.Brand_Name,'') as Brand_Name
from model A
left outer join brand B
on (A.ID_Brand = A.ID_Brand)
left outer join car C on (A.ID_Car) = C.ID_Car