|
 |
|
ช่วยดูโค้ดแบ่งหน้าให้หน่อยครับ หน้าแรกโชว์ข้อมูลได้ตามเงื่อนไข แต่พอเลือกไปหน้าที่ 2 มันเป็นหน้าเปล่า ครับ มีรูปมาให้ดูครับ |
|
 |
|
|
 |
 |
|
ผมลองทำมาหลายวันแล้วครับ ช่วยหน่อยครับ
Code (PHP)
$objConnect = odbc_connect("PWA","sa","software") or die("Error Connect to Database");
if($list=="boxhour")
{
$strQuery="select top 96 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
elseif($list=="boxweek")
{
$strQuery="select top 672 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
elseif($list=="boxmonth")
{
$strQuery="select top 2880 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
$objExec = odbc_exec($objConnect, $strQuery) or die ("Error Execute [".$strQuery."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++;
$Per_Page = 24; // 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;
if($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="400" border="1">
<tr>
<td width="200" align="center" bgcolor="#808080"><strong>วัน - เวลา</strong></td>
<td width="200" align="center" bgcolor="#808080"><strong> <? echo $yaname ?> </strong></td>
</tr>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
<tr>
<!-- <td width="100" ><div align="center"> <?=$no;?> </div></td> -->
<td width="200" ><div align="center"><?=$objResult["namevalue"]; ?> </div></td>
<td width="200" ><div align="center"><?=$objResult["typevalue"]; ?></div></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo "<a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'> Next>></a> ";
}
odbc_close($objConnect);
}


Tag : PHP, Ms SQL Server 2008

|
|
 |
 |
 |
 |
Date :
2012-02-27 11:36:04 |
By :
DEKLAO |
View :
1224 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในตัวอย่างนี้จะเป็นการหาจำนวนข้อมูลแล้วหาจำนวนหน้า
Code (PHP)
<?
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "newproject";
mysql_connect($host, $user, $pass);
mysql_select_db($dbname);
mysql_query("SET NAMES UTF8");
$pagesize = 20;
$sql = "SELECT * FROM student ORDER BY st_id ASC";
$rs = mysql_query($sql);
$total=mysql_num_rows($rs);
$totalpage=ceil($total/$pagesize);
$page=$_GET['page'];
if (!isset($page)) {
$page=1;
$goto=0;
} else {
$goto=($page-1)*$pagesize;
}
$qresult=mysql_query("SELECT * FROM student ORDER BY st_id ASC LIMIT $goto, $pagesize");
?>
อันนี้เป็นโค้ดที่ใช้สำหรับเลือกไปยังหน้าที่ต้องการ ต้องแทรกโค้ดก่อน </table>
<tr bgcolor="FFFFCC">
<?
if ($totalpage>1){
for ($i=1; $i<=$totalpage; $i++){
if ($i==$page){
echo "หน้า $page";
} else {
echo "| <a href=\"studentedit.php?page=$i\">$i</a>";
}
}
}
?>
</tr>
</table>
น่าจะนำไปประยุกต์ได้ ลองดูนะค่ะ
|
 |
 |
 |
 |
Date :
2012-02-27 12:44:58 |
By :
milk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดทั้งหมดครับ ช่วยหน่อยนะครับ
Code (PHP)
<html>
<meta http-equiv=Content-Type content="text/html; charset=windows-874">
<HEAD>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
.text{
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
-->
</style>
</HEAD>
<BODY>
<CENTER>
<? include("list_radio.php");?>
<form name="form1" method="post" >
<table width="1000" height="271" border="1">
<tr width="1000" height="120"> </tr>
<tr>
<td width="250" valign="top">
<div>
<select name="station" id="station" >
<option value=""><? if($station <> ""){echo $station;}else{echo"กรุณาเลือกสถานี";}?></option>
<? getSiteList($link); ?>
</select>
</div>
<div>
<p><strong>ข้อมูลสถิติ</strong> </p>
<div> <input name="type" id="type" type="radio" value="RF_15MIN" <?php if($type == "RF_15MIN") { echo"checked";} ?> >ปริมาณน้ำฝน </div>
<div> <input name="type" id="type" type="radio" value="WL_IN"<?php if($type == "WL_IN") { echo"checked";} ?> >ระดับน้ำ </div>
<div> <input name="type" id="type" type="radio" value="FLOW_IN" <?php if($type == "FLOW_IN") { echo"checked";} ?> >ปริมาณน้ำ </div>
<!-- <? selectradio($link,$station); ?> -->
</div>
</div>
<div>
<p><strong>ช่วงเวลา</strong> </p>
<div> <input name="list" id="list" type="radio" value="boxhour" <?php if($list == "boxhour") { echo"checked";} ?> >ย้อนหลัง 24 ชั่วโมง </div>
<div> <input name="list" id="list" type="radio" value="boxweek" <?php if($list == "boxweek") { echo"checked";} ?> >ย้อนหลัง 7 วัน </div>
<div> <input name="list" id="list" type="radio" value="boxmonth" <?php if($list == "boxmonth") { echo"checked";} ?> > ย้อนหลัง 1 เดือน </div>
</div>
<div> <input type="submit" name="Search" id="Search" value="ค้นหาข้อมูล">
</div>
</td>
<td width="600">
<?
if($station<>"")
{
if($type=="RF_15MIN")
{
$yaname="ปริมาณน้ำฝน มม.";
}
elseif($type=="WL_IN_STAMP")
{
$yaname="ระดับน้ำ ม.รทก.";
}
else
{
$yaname="ปริมาณน้ำ ลบ.ม./วินาที";
}
// Fetch all factory records
$objConnect = odbc_connect("PWA","sa","software") or die("Error Connect to Database");
if($list=="boxhour")
{
$strQuery="select top 96 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
elseif($list=="boxweek")
{
$strQuery="select top 672 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
elseif($list=="boxmonth")
{
$strQuery="select top 2880 convert(varchar(16),(sensordt),120) as namevalue,do as typevalue FROM [PWA].[dbo].[sensor_data]
where site='$station' ";
}
$objExec = odbc_exec($objConnect, $strQuery) or die ("Error Execute [".$strQuery."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++;
$Per_Page = 24; // 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;
if($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
?>
<table width="400" border="1">
<tr>
<td width="200" align="center" bgcolor="#808080"><strong>วัน - เวลา</strong></td>
<td width="200" align="center" bgcolor="#808080"><strong> <? echo $yaname ?> </strong></td>
</tr>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
<tr>
<!-- <td width="100" ><div align="center"> <?=$no;?> </div></td> -->
<td width="200" ><div align="center"><?=$objResult["namevalue"]; ?> </div></td>
<td width="200" ><div align="center"><?=$objResult["typevalue"]; ?></div></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&station=$_post[station]&type=$_post[type]&list=$_post[list]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&station=$_post[station]&type=$_post[type]&list=$_post[list]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo "<a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&station=$_post[station]&type=$_post[type]&list=$_post[list]'> Next>></a> ";
}
odbc_close($objConnect);
}
?>
</td>
</tr>
</table>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-02-27 13:28:03 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยตอบผมหน่อยครับ
|
 |
 |
 |
 |
Date :
2012-02-28 09:17:06 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยหน่อยครับ
|
 |
 |
 |
 |
Date :
2012-02-29 09:28:26 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขออภัยที่ไม่สามารถช่วยดู code ทั้งหมดได้นะครับ แต่ที่น่าสังเกตก็คือ ตอนที่กดหน้า 2 นั้น ให้ดูในช่อง url ของ browser ว่ามันแปลกๆมั้ยครับ เพราะมันส่งค่าได้แค่ตัวแปรเดียว เพราะฉะนั้น ให้ไปไล่ดู code ในขั้นตอนการคลิกเ้พื่อเรียกหน้าต่างๆ ดูว่ามันส่งตัวแปรไปยังไง และถูกต้องหรือเปล่า
|
 |
 |
 |
 |
Date :
2012-02-29 09:34:54 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนจาก $_post เป็น $_REQUEST นะครับ
|
 |
 |
 |
 |
Date :
2012-02-29 10:54:46 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|