 |
พี่คับช่วยดูโค้ดให้หน่อยคับ ผมเชื่อมตาราง กันแล้ว ข้อมูลออกแค่ตารางเดียว |
|
 |
|
|
 |
 |
|
<?
if (empty($keyword))
{
echo"<B>กรอกชื่อสินค้า</B>";
exit();
}
$host="localhost";
$username="root";
$pass_word="";
$db="dbchai";
$tb="product";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
$sql = "SELECT b.*,b.* FROM product a LEFT JOIN company b ON a.com_id = b.com_id WHERE a.pro_title LIKE '%$keyword%'";
/* ตั้งค่า แสดงผลต่อหน้า $Per_Page */
$Per_Page =5; // แสดงหน้าละ 5
if(!$Page)
$Page=1;
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);
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;
if(($Page>$Num_Pages) || ($Page<0))
print "<center><b>จำนวน $Page มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
$sql = "SELECT b.*,b.* FROM product a LEFT JOIN company b ON a.com_id = b.com_id WHERE a.pro_title LIKE '%$keyword%' order by pro_id asc LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
?>
<br>
<br>
</font>
<table width="89%" border="0" cellspacing="1" cellpadding="1" height="37" align="center">
<tr bgcolor="#CAE4FF">
<td width="34%" height="26" bgcolor="#0099FF"> <div align="center"><font color="#FFFFFF" size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">บริษัท / ตัวแทนจำหน่าย </font></div></td>
<td width="31%" height="26" bgcolor="#0099FF"> <div align="center"><font color="#FFFFFF" size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">ชื่อสินค้า</font></div></td>
<td width="14%" height="26" bgcolor="#0099FF"> <div align="center"><font color="#FFFFFF" size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">ระยะประกัน</font></div></td>
<td width="21%" height="26" bgcolor="#0099FF"> <div align="center"><font color="#FFFFFF" size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">ราคา</font></div></td>
</tr>
</table>
<font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">
<?
While($row= mysql_fetch_array($result)){
$com_name = $row["com_name"];
$pro_title = $row["pro_title"];
$pro_time=$row["pro_time"];
$pro_price=$row["pro_price"];
?>
</font>
<table width="89%" border="0" cellspacing="1" cellpadding="1" height="26" align="center">
<tr bgcolor="#EAEAEA">
<td width="34%" height="21"> <div align="center"><font face="Microsoft Sans Serif, MS Sans Serif, sans-serif" size="-1">
<? echo $com_name;?> </font></div></td>
<td width="32%" height="21"> <div align="center"><font face="Microsoft Sans Serif, MS Sans Serif, sans-serif" size="-1">
<? echo $pro_title;?> </font></div></td>
<td width="13%" height="21"> <div align="center"><font face="Microsoft Sans Serif, MS Sans Serif, sans-serif" size="-1">
<? echo $pro_time;?> </font></div></td>
<td width="21%" height="21"> <div align="center"><font face="Microsoft Sans Serif, MS Sans Serif, sans-serif" size="-1">
<? echo $pro_price;?> </font></div></td>
</tr>
</table>
<font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif">
<? }?>
</font>
<div align="center"> <font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><br>
<font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font color="#0000FF">พบทั้งหมด<b></b></font></font><font color="#0000FF"><b></b></font></font><font color="#0000FF"><b>
<?= $Num_Rows;?>
</b> </font><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font color="#0000FF">รายก</font></font><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font color="#0000FF">าร</font></font><font color="#0000FF">รวมทั้งหมด</font></font><font color="#0000FF"></font></font><font color="#0000FF">
: <b>
<?=$Num_Pages;?>
</b> </font><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font size="-1" face="Microsoft Sans Serif, MS Sans Serif, sans-serif"><font color="#0000FF">หน้า</font></font><font color="#0000FF"></font></font><font color="#0000FF">
:
<? /* สร้างปุ่มย้อนกลับ */
if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page&keyword=$keyword'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $Page)
echo "[<a href='$PHP_SELF?Page=$i&keyword=$keyword'>$i</a>]";
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($Page!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page&keyword=$keyword'> หน้าถัดไป>> </a>";
mysql_close();
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-05-18 16:29:52 |
By :
อยากจบจัง |
View :
1292 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่วินคับ ขอบคุณมากคับ ออกแว้วครับ ดีใจจัง
|
 |
 |
 |
 |
Date :
2009-05-18 20:28:53 |
By :
หิวมั้ย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|