Error Query [select a.* ,b.p_num,c.p_adv_numkey , c.p_adv_fname , c.p_adv_sname, e.p_gra_w ,f.p_aca_w from senior_n a left join senior_num b on a.p_numkey = b.p_numkey left join senior_adv c on a.p_adv = c.p_adv left join senior_gra e on a.p_gra = e.p_gra left join senior_aca f on a.p_aca = f.p_aca WHERE ( p_name LIKE '%54%' or p_id LIKE '%54%' p_stu_fname LIKE '%54%' or p_stu_sname LIKE '%54%' p_aca_w LIKE '%54%' or p_adv_fname LIKE '%54%' p_adv_sname LIKE '%54%' or p_gra_w LIKE '%54%')]
Code (PHP)
<html>
<head>
<title>ค้นหา</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
if($_GET["txtKeyword"] != "")
{
include("connect.php");
// 3. นำคำสั่ง sql ไปทำการประมาวลผลที่ฐานข้อมูล
$sql ="select a.* ,b.p_num,c.p_adv_numkey , c.p_adv_fname , c.p_adv_sname, e.p_gra_w ,f.p_aca_w from senior_n a
left join senior_num b on a.p_numkey = b.p_numkey
left join senior_adv c on a.p_adv = c.p_adv
left join senior_gra e on a.p_gra = e.p_gra
left join senior_aca f on a.p_aca = f.p_aca
WHERE ( p_name LIKE '%".$_GET["txtKeyword"]."%' or p_id LIKE '%".$_GET["txtKeyword"]."%'
p_stu_fname LIKE '%".$_GET["txtKeyword"]."%' or p_stu_sname LIKE '%".$_GET["txtKeyword"]."%'
p_aca_w LIKE '%".$_GET["txtKeyword"]."%' or p_adv_fname LIKE '%".$_GET["txtKeyword"]."%'
p_adv_sname LIKE '%".$_GET["txtKeyword"]."%' or p_gra_w LIKE '%".$_GET["txtKeyword"]."%')";
$objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 20; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$sql .=" order by p_id ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($sql);
?>
<table width="1250" align="center" class="square">
<tr bgcolor="#A8A8A8">
<td width="61" height="68" align="center"><strong>รหัส Senior Project</strong></td>
<td width="312" align="center"><strong>ชื่อ Senior Project</strong></td>
<td width="206" align="center"><strong>ชื่อนักเรียน</strong></td>
<td width="208" align="center"><strong>ชื่ออาจารย์ที่ปรึกษา</strong></td>
<td width="89" align="center"><strong>ระดับคะแนน</strong></td>
<td width="82" align="center"><strong>ปีการศึกษา</strong></td>
<td width="81" align="center"><strong>บทคัดย่อ</strong></td>
<td width="70" align="center"><strong>แก้ไข</strong></td>
<td width="65" align="center"><p><strong>แก้บท</strong><strong>คัดย่อ</strong></p>
</td>
<td width="32" align="center"><strong>ลบ</strong></td>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["p_id"];?></div></td>
<td><div align="left"><?=$objResult["p_name"];?></div></td>
<td><div align="left"><?=$objResult["p_num"];?><?=$objResult["p_stu_fname"];?><?=$objResult["p_stu_sname"];?></div></td>
<td><div align="left"><?=$objResult["p_adv_numkey"];?><?=$objResult["p_adv_fname"];?><?=$objResult["p_adv_sname"];?></div></td>
<td><div align="center"><?=$objResult["p_gra_w"]; ?> </div></td>
<td><div align="center"><?=$objResult["p_aca_w"]; ?></div></td>
<td><div align="center"><a href="abs/<?=$objResult["p_abs_name"];?>" target='_blank'>
<?=$objResult["p_abs_name"];?>
</a></div></td>
<td><div align="center"><a href="editform.php?p_id=<?=$objResult["p_id"] ?>" target='_blank' >แก้ไข</a></div></td>
<td><div align="center"><a href="editabs.php?p_id=<?=$objResult["p_id"] ?>" target='_blank' >แก้</a></div></td>
<td><a href="delete.php?p_id=<?=$objResult['p_id'] ?>"
onclick="return confirm('are u sure??');">ลบ</a></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}
mysql_close($objConnect);
}
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, CakePHP, Crystal Report