|
 |
|
ค้นหาและแสดงผลแบ่งหน้าใน SQLServer ครับ คำสั่ง mysql นะครับ |
|
 |
|
|
 |
 |
|
ใหม่นะครับ
<?
$sql = "SELECT * FROM table WHERE Name LIKE '%$select%' order byname LIMIT 2,4";
?>
คำสั่งใน SQLServer นะครับ ประมาณนี้นะครับ คือแบ่งหน้าได้แล้วครับกรณีค้นหาทั้งหมด ปัญหาก็คือ กรณีที่ค้นหาแบบมีเงื่อนไข มันยังไม่ได้เลยอะครับ รบกวนด้วยนะครับ ตอนนี้งานเร่งมากเลยอ่ะครับ
<?
$sql = "SELECT TOP 4 * FROM TABLE WHERE DOC_ID NOT IN(SELECT TOP 2 DOC_ID FROM TABLE ORDER BY Rev DESC)ORDER BY Rev DESC";
?>
|
 |
 |
 |
 |
Date :
2009-09-03 09:26:10 |
By :
sandiago |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกนิดนะครับ
ใช้ PHP + SQL Server ( ODBC )
รบกวนด้วยครับผม หายากมากเลยในเว็บอะครับ หาเจอแต่ PHP + SQL Server (mssql)
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-09-03 10:14:43 |
By :
sandiago |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
PHP Microsoft Access ใช้ ODBC ครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & Access 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 = odbc_connect("mydatabase","","") or die("Error Connect to Database");
// Search By Name or Email
$strSQL = "SELECT * FROM customer WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or Email LIKE '%".$_GET["txtKeyword"]."%' )";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++; // Count Record
$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)+1;
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;
}
$Page_End = $Per_Page * $Page;
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></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> ";
}
odbc_close($objConnect);
}
?>
</body>
</html>

|
 |
 |
 |
 |
Date :
2009-09-03 10:18:13 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|