|
 |
|
ผมเอาตัวอย่างที่สอนจากเว็บไปทำดูครับ แต่เกิดปัญหาครับผมเกี่ยวกับ PHP MySQL Search Record Paging |
|
 |
|
|
 |
 |
|
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</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"] != "")
{
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("book1");
// Search By Name or Email
$strSQL = "SELECT * FROM book1 WHERE (TITLE LIKE '%".$_GET["txtKeyword"]."%' or PCODE2 LIKE '%".$_GET["txtKeyword"]."%')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 2; // 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;
}
$strSQL2= "SELECT * FROM book1 WHERE (TITLE LIKE '%".$_GET["txtKeyword"]."%' or PCODE2 LIKE '%".$_GET["txtKeyword"]."%')";
$strSQL2.=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
$objQuery2 = mysql_query($strSQL2);
?>
<table width="1200" border="1">
<tr>
<th width="300"> <div align="center">TITLE</div></th>
<th width="300"> <div align="center">ITYPE</div></th>
<th width="300"><div align="center">LOCATION</div></th>
<th width="300"><div align="center">OUTDATE</div></th>
<th width="300"><div align="center">DUEDATE</div></th>
<th width="300"><div align="center">PATRNNAME</div></th>
<th width="300"><div align="center">PCODE2</div></th>
<th width="300"> <div align="center">TOTCHKOUT</div></th>
<th width="300"> <div align="center">BARCODE</div></th>
<th width="300"> <div align="center">PBARCODE</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery2))
{
?>
<tr>
<td><div align="center"><?=$objResult["TITLE"];?></div></td>
<td><?=$objResult["ITYPE"];?></td>
<td><?=$objResult["LOCATION"];?></td>
<td><div align="center"><?=$objResult["OUTDATE"];?></div></td>
<td><div align="center"><?=$objResult["DUEDATE"];?></div></td>
<td><div align="center"><?=$objResult["PATRNNAME"];?></div></td>
<td><div align="center"><?=$objResult["PCODE2"];?></div></td>
<td><div align="center"><?=$objResult["TOTCHKOUT"];?></div></td>
<td align="right"><?=$objResult["BARCODE"];?></td>
<td align="left"><?=$objResult["PBARCODE"];?></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>
|
 |
 |
 |
 |
Date :
2009-08-10 19:38:14 |
By :
avaegee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังเป็นเหมือนเดิมครับ เหมือนตอนแรกที่มีปัญหาครับ
ยังไงขอบคุณท่านข้างบนด้วยนะครับที่มาช่วยครับ
|
 |
 |
 |
 |
Date :
2009-08-10 20:46:59 |
By :
nuttapont |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆครับ
|
 |
 |
 |
 |
Date :
2009-08-10 23:30:42 |
By :
nuttapont |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|