|
|
|
แบ่งคอลัมภ์ให้หน่อยครับ ตอนนี้มีแบ่งหน้า และ เลขหน้าแล้ว |
|
|
|
|
|
|
|
ตอนนี้มีฟังชั่น แบ่งหน้า และมีเลขหน้าแบบ google แล้ว แต่อยากได้แบบ ที่สามารถแบ่งคอลัมภ์ได้ด้วยนะครับ
Code (PHP)
<?php
include("include/phpConfig.inc.php");
$objconn = new Conn();
$objdate = new Date();
$Headerto=new Header_goto();
$objReport = new Report();
$objSecurity = new Security();
$objconn->Conn2DB();
?>
<?php
// สร้างฟังก์ชั่น สำหรับแสดงการแบ่งหน้า
function page_navigator($before_p,$plus_p,$total,$total_p,$chk_page){
global $urlquery_str;
$pPrev=$chk_page-1;
$pPrev=($pPrev>=0)?$pPrev:0;
$pNext=$chk_page+1;
$pNext=($pNext>=$total_p)?$total_p-1:$pNext;
$lt_page=$total_p-4;
if($chk_page>0){
echo "<a href='?s_page=$pPrev&urlquery_str=".$urlquery_str."' class='naviPN'>Prev</a>";
}
if($total_p>=11){
if($chk_page>=4){
echo "<a $nClass href='?s_page=0&urlquery_str=".$urlquery_str."'>1</a><a class='SpaceC'>. . .</a>";
}
if($chk_page<4){
for($i=0;$i<$total_p;$i++){
$nClass=($chk_page==$i)?"class='selectPage'":"";
if($i<=4){
echo "<a $nClass href='?s_page=$i&urlquery_str=".$urlquery_str."'>".intval($i+1)."</a> ";
}
if($i==$total_p-1 ){
echo "<a class='SpaceC'>. . .</a><a $nClass href='?s_page=$i&urlquery_str=".$urlquery_str."'>".intval($i+1)."</a> ";
}
}
}
if($chk_page>=4 && $chk_page<$lt_page){
$st_page=$chk_page-3;
for($i=1;$i<=5;$i++){
$nClass=($chk_page==($st_page+$i))?"class='selectPage'":"";
echo "<a $nClass href='?s_page=".intval($st_page+$i).$_SESSION['ses_qCurProvince']."'>".intval($st_page+$i+1)."</a> ";
}
for($i=0;$i<$total_p;$i++){
if($i==$total_p-1 ){
$nClass=($chk_page==$i)?"class='selectPage'":"";
echo "<a class='SpaceC'>. . .</a><a $nClass href='?s_page=$i&urlquery_str=".$urlquery_str."'>".intval($i+1)."</a> ";
}
}
}
if($chk_page>=$lt_page){
for($i=0;$i<=4;$i++){
$nClass=($chk_page==($lt_page+$i-1))?"class='selectPage'":"";
echo "<a $nClass href='?s_page=".intval($lt_page+$i-1).$_SESSION['ses_qCurProvince']."'>".intval($lt_page+$i)."</a> ";
}
}
}else{
for($i=0;$i<$total_p;$i++){
$nClass=($chk_page==$i)?"class='selectPage'":"";
echo "<a href='?s_page=$i&urlquery_str=".$urlquery_str."' $nClass >".intval($i+1)."</a> ";
}
}
if($chk_page<$total_p-1){
echo "<a href='?s_page=$pNext&urlquery_str=".$urlquery_str."' class='naviPN'>Next</a>";
}
}
?>
<?php
$q="select * from tbsubproduct where 1";
$q.=" ORDER BY sub_id ";
$qr=mysql_query($q);
$total=mysql_num_rows($qr);
$e_page=3; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า
if(!isset($s_page)){
$s_page=0;
}else{
$chk_page=$s_page;
$s_page=$s_page*$e_page;
}
$q.=" LIMIT $s_page,$e_page";
$qr=mysql_query($q);
if(mysql_num_rows($qr)>=1){
$plus_p=($chk_page*$e_page)+mysql_num_rows($qr);
}else{
$plus_p=($chk_page*$e_page);
}
$total_p=ceil($total/$e_page);
$before_p=($chk_page*$e_page)+1;
?>
<?php
while($rs=mysql_fetch_array($qr)){
$q2="select * from tbrproduct where pa_id='".$rs["sub_id"]."' order by r_id asc limit 0,1";
$queryrows=mysql_query($q2);
$rsrows=mysql_fetch_array($queryrows);
?>
<table width="540" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td width="140" rowspan="2" valign="top"><a href="detail_page.php?sub_id=<?php echo $rs["sub_id"]?>" title="<?php echo $rs_sp["location_name"]?>" target="_blank"><img src="pic_thumbnail/<?php echo $rs["pic_thumbnail"]?>" width="140" height="96" border="0" class="imgborder" /></a></td>
<td valign="top" class="txtadmin-dot2"> <b><a href="detail_page.php?sub_id=<?php echo $rs["sub_id"]?>" title="<?php echo $rs["location_name"]?>" target="_blank">
<?php echo $rs["location_name"]?>
</a></b></td>
</tr>
<tr>
<td valign="top" class="txtadmin"><?php //$text = substr($rsrows["descript"],0,150);
$text = mb_substr($rsrows["descript"],0,400,'utf-8');
$text2= ereg_replace("</?[a-z][a-z0-9]*[^<>]*>","", $text);
echo $text2 ."...";
?>
<br />
<a href="detail_page.php?sub_id=<?php echo $rs["sub_id"]?>">More...</a></td>
</tr>
<tr>
<td colspan="2" valign="top"><span class="txtadmin"><img src="images/px.gif" width="10" height="5" /></span></td>
</tr>
</table>
<?php } ?>
<?php if($total>0){ ?>
<div align="right" class="browse_page">
<?php
// เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า
page_navigator($before_p,$plus_p,$total,$total_p,$chk_page);
?>
</div>
<?php } ?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-08-27 10:49:38 |
By :
ต้อง |
View :
1125 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Multiple Column</title>
</head>
<body>
<div align="center">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM gallery ORDER BY GalleryID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
echo "<td>";
?>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="gallery/<?=$objResult["Picture"];?>" target="_blank"><img src="gallery/<?=$objResult["Thumbnails"];?>" width="70" height="53" border="0"></a></div></td>
</tr>
<tr>
<td><div align="center"><?=$objResult["GalleryName"];?></div></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%2==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?
mysql_close($objConnect);
?>
</div>
</body>
</html>
|
|
|
|
|
Date :
2009-08-27 11:39:24 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _autopage($page_sql,$page_size,$page,$url){
if($page_size=="" || $page_size==0){
$page_size=15;
}
if($page==""){
$page=1;
}
$psize=$page_size;
$page_query=mysql_query($page_sql);
$page_num=mysql_num_rows($page_query);
$rt = $page_num%$page_size;
if($rt!=0){
$total_page = floor($page_num/$page_size)+1;
}
else {
$total_page = floor($page_num/$page_size);
}
/* $startrow=($page*$page_size)-$page_size;
$stoprow=($page*$page_size)-1;
if($stoprow>$page_num){
$stoprow=$page_num;
}
*/
$page_start = ($page-1)*$page_size;
if($page_start <0)$page_start =0;
$page_sql.=" limit $page_start,$page_size";
$page_db=mysql_query($page_sql)or die(mysql_error());
/* if($page_num>0){
_data_seek($page_db,$page_start);
}
*/ //////////////////////////////////////////////////////////
$TB=_pagenext($page_size,$page,$total_page,$url);
//////////////////////////////////////////////////////////
$count=array($page_db,$TB);
return $count;
}//end function _autopage
function _pagenext($page_size,$page,$total_page,$url){
//////////////////////////////////////////////////////////
if($total_page>1){
$TB="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" align=\"center\">";
$TB.=" <tr>";
$TB.=" <td height=\"15\" colspan=\"2\" ><hr style=\"color:#6F6F9F; border:dotted;\" size=1>";
$TB.=" </td>";
$TB.=" </tr>";
$TB.=" <tr>";
$TB.=" <td align=\"right\" colspan=\"2\" height=\"15\">";
if($page!=1){
$TB.=" <font color=\"#6F6F9F\"> [ <a href=\"?page=".($page-1)."&".$url." \"><b>back</b></a> ] </font>";
}
if($page!=$total_page){
$TB.=" <font color=\"#6F6F9F\"> [ <a href=\"?page=".($page+1)."&".$url." \"><b>next</b></a> ] </font>";
}
$TB.=" </td>";
$TB.=" </tr>";
$TB.=" <tr>";
$TB.=" <td height=\"15\">";
$TB.=" <font color=\"#6F6F9F\">$sub_18 <b><font color=\"#6F6F9F\">$page</font></b> / <b><font color=\"#6F6F9F\">".$total_page."</font></b> </font>";
$TB.=" </td>";
$TB.=" <td align=\"right\" height=\"15\">";
$TB.=" <font color=\"#6F6F9F\"><b> $sub_18 </b></font>";
/******************************************************/
$MAXLIMIT=10;//$page_size;
$PMAX=$total_page;
if($page==""){$page=1;}
if($page%$MAXLIMIT==0){
$Tnum=$page-1;
}else{
$num=(($page-($page%$MAXLIMIT))/$MAXLIMIT);
if($num==0){
$Tnum=1;
}else{
$Tnum=($num*$MAXLIMIT)-1;
}
}
if(($Tnum+$MAXLIMIT)>$PMAX){
$MAX=$PMAX;
}elseif($page<$MAXLIMIT){
$MAX=($Tnum+$MAXLIMIT)-1;
}else{
$MAX=($Tnum+$MAXLIMIT)+1;
}
for($i=$Tnum ; $i<=($MAX); $i++){
if($page==$i){
$TB.=" <font color=\"#FF0000\"><b>[$page]</b></font> ";
}elseif($i==$Tnum){
$TB.=" <font color=\"#FFFFFF\">[<a href=\"?page=$i&".$url."\">$i</a>]</font> ";
}else{
$TB.=" <font color=\"#FFFFFF\">[<a href=\"?page=$i&".$url."\">$i</a>]</font> ";
}
}
/******************************************************/
$TB.=" </td>";
$TB.=" </tr>";
$TB.="</table>";
}else{
$TB.="";
}
//////////////////////////////////////////////////////////
return $TB;
}//end function pagenext
อ่านเพิ่มเติ่มได้ที่ http://www.thaiems.net
|
|
|
|
|
Date :
2009-08-27 11:49:31 |
By :
konlata |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้จากโค๊ดเดิมได้ไหมครับ ยังไม่ถึงขั้นนะครับ
|
|
|
|
|
Date :
2009-08-31 16:47:35 |
By :
ต้อง2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|