ช่วยด้วยครับ ทำ search ข้อมูลในฐานข้อมูลไม่ได้ครับ
Code (PHP)
<?
include ("connectDB.php");
$cond = "";
if($_POST["search"] != "")
{
$cond = $cond . " AND (ThName like '%" . $_POST["search"] . "%'
OR Level like '%" . $_POST["search"] . "%'
OR QuaName like '%" . $_POST["search"] . "%'
OR CategoryName like '%" . $_POST["search"] . "%'
OR PositionName like '%" . $_POST["search"] . "%'
OR ProvinceId like '%" . $_POST["search"] . "%')
";
}
if($_POST["CategoryId"] != "")
{
$cond = $cond . " AND CategoryId = " . $_POST["CategoryId"];
}
if($_POST["PositionId"] != "")
{
$cond = $cond . " AND PositionId = " . $_POST["PositionId"];
}
if($_POST["Level"] != "")
{
$cond = $cond . " AND Level = " . $_POST["Level"];
}
if($_POST["QuaId"] != "")
{
$cond = $cond . " AND a2.QuaId = " . $_POST["QuaId"];
}
if($_POST["StartSalary"] != "")
{
$cond = $cond . " AND StartSalary = " . $_POST["StartSalary"];
}
if($_POST["EndSalary"] != "")
{
$cond = $cond . " AND EndSalary = " . $_POST["EndSalary"];
}
if($_POST["ProvinceId"] != "")
{
$cond = $cond . " AND ProvinceId = " . $_POST["ProvinceId"];
}
if($_POST["DistinctId"] != "")
{
$cond = $cond . " AND DistinctId = " . $_POST["DistinctId"];
}
$sql = "SELECT * FROM announce a1, anneducation a2, qualification a3 , entrepreneur a4 , province a5 , category a6 , position a7 , distinct a8
WHERE a1.AnnounceId = a2.AnnounceId
AND a2.QuaId = a3.QuaId
AND a1.EntreId = a4.EntreId
AND a1.CategoryId = a6.CategoryId
AND a1.PositionId = a7.PositionId
AND a1.DistinctId = a8.DistinctId
AND a1.ProvinceId = a5.ProvinceId $cond";
$result = mysql_query($sql) or die ("Error Query [".$sql."]");
$Num_Rows = mysql_num_rows($result);
echo $sql;
while($row = mysql_fetch_array($result))
{
?>
<table width="700" align="center" bgcolor="#CCCCCC">
<tr><td width="100"><font color="#0033FF">บริษัท:</font></td><td><? echo $row['ThName']; ?></td>
<tr><td width="100"><font color="#0033FF">ตำแหน่งงาน :</font></td><td><? echo $row['PositionName']; ?></td>
<td width="100"><font color="#0033FF">ประเภทงาน :</font></td><td><? echo $row['CategoryName']; ?></td><td rowspan="2" align="right"><a href="#"><img src="images/address_book.png"/></a></td>
</tr>
<tr><td width="100"><font color="#0033FF">วันที่ลงประกาศ:</font></td><td><? echo $row['OpenAnn']; ?></td><td width="100"><font color="#0033FF">สิ้นสุดวันที่ :</font></td><td><font color="#FF0000"><? echo $row['CloseAnn']; ?></font></td></tr>
</table>
<hr width="700" />
<? } ?>
ทำแล้วมันขึ้น error query ครับ ผมแก้ไขยังไงครับ ช่วยหน่อยนะครับ งานเร่งด่วนมาก
Error Query [SELECT * FROM announce a1, anneducation a2, qualification a3 , entrepreneur a4 , province a5 , category a6 , position a7 , distinct a8 WHERE a1.AnnounceId = a2.AnnounceId AND a2.QuaId = a3.QuaId AND a1.EntreId = a4.EntreId AND a1.CategoryId = a6.CategoryId AND a1.PositionId = a7.PositionId AND a1.DistinctId = a8.DistinctId AND a1.ProvinceId = a5.ProvinceId ]Tag : PHP
Date :
2014-02-28 09:21:10
By :
falcaoza
View :
768
Reply :
4
ลองเอาไปหาดีบัคใน php myadmin ดูครับ เผื่อจะหาบั๊คง่ายขึ้น
Date :
2014-02-28 09:55:04
By :
Dragons_first
คำแนะนำ การเขียน SQL Query Join multiple tables (คุณไม่จำเป็นต้องทำตามก็ได้)
Code (SQL)
Select a1.*, a2.*, a3.*, ..., a8.* From t1 As a1
Inner Join t2 As a2 On a2.CategoryID = a1.CategoryID
Inner Join t3 As a3 On a3.ColumnName = a2.ColumnName
Inner Join t4 As a4 On a4.ColumnName = a3.ColumnName
...
...
...
Inner Join t8 As a8 On a8.ColumnName = a7.ColumnName
WHERE a1.CategoryID = อะไรก็ว่าไป AND a2.ColumnName = อะไรก็ว่าไป
[x] สังเกตุว่า มันแยก WHERE และ JOIN ออกจากกันอย่างชัดเจน
Date :
2014-02-28 12:10:43
By :
love9713
Load balance : Server 01