รบกวนช่วยแก้ให้ทีครับไม่ทราบว่า จะแบ่งหน้าได้ยังไง คือผมลองแบ่งแล้วมันขึ้นแต่หน้า 1
โค๊ดนี้ผมไม่ได้เขียนเองตั้งแต่แรกคือจ้างเขาเขียนแล้ว พอใช้ไปนานๆหน้ามันเยอะผมเลย ต้องการจะแบ่งหน้า เลยมานั่งหาวิธีดูแต่มันยากเหลือเกินสำหรับมือใหม่เช่นผม
<?
$host='localhost';
$user='root';
$pwd='root';
$db='test';
$con=mysql_connect($host,$user,$pwd) or die ("Can not connecting Server");
mysql_select_db($db) or die ("ไม่สามารถเชื่อมต่อไปยังฐานข้อมูลได้".mysql_error());
if($searchtype=="")
{
$callroute="select * from route";
$runcallroute=mysql_query($callroute);
while($route=mysql_fetch_row($runcallroute))
{
$d_datepattern=jdtogregorian($route[3]);
$d_firstslash=strpos($d_datepattern,'/');
$d_lastslash=strrpos($d_datepattern,'/');
$d_totalchr=strlen($d_datepattern);
$d_lastposition=$d_totalchr-1;
$d_gapslash=($d_lastslash-$d_firstslash)-1;
$d_date=substr($d_datepattern,$d_firstslash+1,$d_gapslash);
$d_month=substr($d_datepattern,0,$d_firstslash);
$d_year=substr($d_datepattern,-4);
switch ($d_month){
case "1";{$d_month="January"; break;};
case "2";{$d_month="February"; break;};
case "3";{$d_month="March"; break;};
case "4";{$d_month="April"; break;};
case "5";{$d_month="May"; break;};
case "6";{$d_month="June"; break;};
case "7";{$d_month="July"; break;};
case "8";{$d_month="August"; break;};
case "9";{$d_month="September"; break;};
case "10";{$d_month="October"; break;};
case "11";{$d_month="November"; break;};
case "12";{$d_month="December"; break;};
};
$a_datepattern=jdtogregorian($route[5]);
$a_firstslash=strpos($a_datepattern,'/');
$a_lastslash=strrpos($a_datepattern,'/');
$a_totalchr=strlen($a_datepattern);
$a_lastposition=$a_totalchr-1;
$a_gapslash=($a_lastslash-$a_firstslash)-1;
$a_date=substr($a_datepattern,$a_firstslash+1,$a_gapslash);
$a_month=substr($a_datepattern,0,$a_firstslash);
$a_year=substr($a_datepattern,-4);
switch ($a_month){
case "1";{$a_month="January"; break;};
case "2";{$a_month="February"; break;};
case "3";{$a_month="March"; break;};
case "4";{$a_month="April"; break;};
case "5";{$a_month="May"; break;};
case "6";{$a_month="June"; break;};
case "7";{$a_month="July"; break;};
case "8";{$a_month="August"; break;};
case "9";{$a_month="September"; break;};
case "10";{$a_month="October"; break;};
case "11";{$a_month="November"; break;};
case "12";{$a_month="December"; break;};
};
$depart_date="$d_month $d_date, $d_year";
$arrv_date="$a_month $a_date, $a_year";
$callsubroute="select * from routedetails where route_id='$route[0]' order by rank";
$runcallsubroute=mysql_query($callsubroute);
$numsubroute=mysql_num_rows($runcallsubroute);
$rowheight=$numsubroute+1;
//เริ่มต้นโค๊ดแบ่งหน้า
$pagesize = 20; // แสดงจำนวนกระทู้ในแต่ละหน้า ในที่นี้จะแสดง 20 กระทู้
$totalpage = (int)($numsubroute/$pagesize); // // หาจำนวนหน้าทั้งหมด
// ถ้าจำนวนหน้าเป็นเศษให้ปัดขึ้นไป
if(($numsubroute%$pagesize)!=0){
$totalpage+= 1;
}
// หา record แรกที่จะแสดงของแต่ละหน้า
if(isset($page)){
$pageno = $page;
$start = $pagesize*($pageno-1);
}else{
$pageno = 1;
$start = 0;
}
// ตัวแปร $start เป็นค่าที่เริ่มแสดงกระทู้ ส่วนตัวแปร $pagesize ให้แสดงกี่กระทู้
$callsubroute = "select * from routedetails limit $start,$pagesize";
//สิ้นสุดโค๊ด //ช่วงที่ผมคิดว่าผมแก้ผิด
echo "
<br>
<table width=\"670\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" align=\"center\">
<tr height=\"1\">
<td width=\"70\"></td>
<td width=\"60\"></td>
<td colspan=\"5\" width=\"300\"></td>
<td colspan=\"2\" width=\"120\"></td>
<td colspan=\"2\" width=\"120\"></td>
</tr>
<tr bgcolor=\"#BEBE7E\">
<td align=\"center\" width=\"70\>CODE</td>
<td align=\"center\" width=\"60\">Book<td>
<td colspan=\"5\" align=\"center\" width=\"300\">Detail</td>
<td colspan=\"2\" align=\"center\" width=\"120\">Dep</td>
<td colspan=\"2\" align=\"center\" width=\"120\">Arr.</td>
</tr>
<tr bgcolor=\"#EEEEEE\">
<td align=\"center\" width=\"70\">$route[0]</td>
<td align=\"center\" width=\"60\">$route[18]</td>
<td colspan=\"5\" width=\"300\">$route[1] - $route[2]</td>
<td colspan=\"2\" align=\"center\" width=\"120\">$depart_date</td>
<td colspan=\"2\" align=\"center\" width=\"120\">$arrv_date</td>
</tr>
<tr bgcolor=\"#CFCF9E\">
<td align=\"center\" width=\"70\">Price</td>
<td align=\"center\" width=\"60\">A_Lv1</td>
<td align=\"center\" width=\"60\">A_Lv2</td>
<td align=\"center\" width=\"60\">A_Lv3</td>
<td align=\"center\" width=\"60\">A_Lv4</td>
<td align=\"center\" width=\"60\">A_Lv5</td>
<td align=\"center\" width=\"60\">A_Lv6</td>
<td align=\"center\" width=\"60\">A_Lv7</td>
<td align=\"center\" width=\"60\">A_Lv8</td>
<td align=\"center\" width=\"60\">A_Lv9</td>
<td align=\"center\" width=\"60\">A_Lv10</td>
</tr>
<tr bgcolor=\"#EEEEEE\">
<td align=\"center\" width=\"70\">$route[7]</td>
<td align=\"center\" width=\"60\">$route[8]</td>
<td align=\"center\" width=\"60\">$route[9]</td>
<td align=\"center\" width=\"60\">$route[10]</td>
<td align=\"center\" width=\"60\">$route[11]</td>
<td align=\"center\" width=\"60\">$route[12]</td>
<td align=\"center\" width=\"60\">$route[13]</td>
<td align=\"center\" width=\"60\">$route[14]</td>
<td align=\"center\" width=\"60\">$route[15]</td>
<td align=\"center\" width=\"60\">$route[16]</td>
<td align=\"center\" width=\"60\">$route[17]</td>
</tr>
<tr bgcolor=\"#D1D1D1\">
<td align=\"center\" width=\"70\">Round</td>
<td align=\"center\" width=\"60\">Route;</td>
<td colspan=\"5\" align=\"center\" width=\"300\">Route Detail</td>
<td align=\"center\" width=\"60\">Dep</td>
<td align=\"center\" width=\"60\">Arr</td>
<td bgcolor=\"#E7E7CF\" colspan=\"2\" rowspan=\"$rowheight\" align=\"center\"><a href=\"editrouteform.php?route_id=$route[0]\">á¡éä¢</a> <a href=\"delroute.php?route=$route[0]\">ź</a></td>
</tr>
";
while($subroute=mysql_fetch_row($runcallsubroute))
{
$callsubtrans="select * from schedule where round_id='$subroute[1]'";
$runcallsubtrans=mysql_query($callsubtrans);
while($subtrans=mysql_fetch_row($runcallsubtrans))
{
echo "
<tr bgcolor=\"#EEEEEE\">
<td align=\"center\" width=\"70\">$subtrans[0]</td>
<td align=\"center\" width=\"60\">$subtrans[2]</td>
<td colspan=\"5\" width=\"300\">$subtrans[3] - $subtrans[4]</td>
<td align=\"right\" width=\"60\">$subtrans[6] </td>
<td align=\"right\" width=\"60\">$subtrans[8] </td>
</tr>
";
};
};
};
echo "</table>";
if($pageno >1){
echo " <a href='view.php?page=",$pageno-1,"'>Previous</a> |";
}
for($i=1;$i<=$totalpage;$i++){
if($pageno==$i){
echo" <b>".$i."</b> |";
}else{
echo " <a href='view.php?page=$i'>$i</a> |";
}
}
if($pageno<$totalpage){
echo " <a href='view.php?page=",$pageno+1,"'>Next</a>";
}
}
?>
ป.ล. มันดึงข้อมูล จาก 3 ตาราง มาใส่ ไม่เคยเจอในหนังสือก็ไม่มี มือใหม่ตกม้าตาย -''-
Tag : - - - -
Date :
30 ม.ค. 2551 19:25:20
By :
figgaro
View :
1167
Reply :
2
$callsubroute="select * from routedetails order by rank";
Date :
30 ม.ค. 2551 20:20:06
By :
arsachi
select หลายทีจังฮู้
++++++++++++++ ++++++
Date :
31 ม.ค. 2551 08:30:58
By :
ไอเซนการ์ด
Load balance : Server 02