|
|
|
ติดปัญหาการค้นหา search เป็นเพจ Page เลขที่ของหน้า ครับ |
|
|
|
|
|
|
|
ติดปัญหาการค้นหา search เป็นเพจ Page ครับ
คือ ผมส่งค่า GET (p_ebook/category_p_ebook.php?id=15) แบบนี้มาครับ
มันจะแสดงค่า cms_category_eb.ceb_id ตามหมวดหมู่ที่ส่งมา และค้นหาชื่อ eb_iddoc หรือ eb_title ก็ถูกต้องแล้วนะครับ
แต่ปัญหา คือ พอค้นหา eb_iddoc หรือ eb_title แล้วกด เลขหน้าที่ page มันจะแสดงทั้งหมดของรายการ
ตัวอย่าง
สมมุติว่า ผมค้นหา คำว่า '0002' พอกดค้นหาแล้วก็จะแสดงเพียง 3 หน้า มีทั้งหมด 10 รายการ แต่ถ้าผมกด เลขที่ของหน้า เลขใดก็ได้ครับ พอกดแล้ว มันจะแสดงรายการที่มีทั้งหมด 100 รายการ ครับ
ผมอยากได้แบบกด เลขที่ของหน้า ตามที่เราได้ทำการค้นหาไว้ครับ
Code (PHP)
<!-- /////////////////////////////// From Webpage /////////////////////////////// -->
<table id="broder-table" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#E9E9E6" bgcolor="#FFFFFF">
<tr>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="100%" border="0" bgcolor="#FFFFFF">
<div align="center">
<div id="broder-table1" align="left" style="width: 725px">
<form id="frmSearch" name="frmSearch" method="get" action="category_p_ebook.php"><span class="style2"> Filter (ID Doc. or Title)</span>
<input name="txtsearch" type="text" class="input_box" id="txtsearch" size="35" value="<?php echo @$_GET['txtsearch']?>" />
<input type="submit" name="button2" id="button2" value="Search" />
</form>
</div>
</div>
<tr>
<td>
<table width="735" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
<tr>
<td height="16" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
</tr>
<tr>
<td>
<tr bgcolor="#003399">
<th height="36" colspan="15" bgcolor="" scope="col" align="center">
<span class="style1"><p class="head1">Search E-Book List</p></span></th>
</tr>
<tr class="head1" bgcolor="#0066CC">
<th align="center" class="head1" width="4%">No.</th>
<th align="center" class="head1" width="10%">ID Doc.</th>
<th align="center" class="head1" width="35%">Title</th>
<th align="center" class="head1" width="6%">Group</th>
<th align="center" class="head1" width="13%">Category</th>
<th align="center" class="head1" width="11%">Created</th>
<th align="center" class="head1" width="11%">Created by</th>
<th align="center" class="head1" width="5%">File</th>
<th align="center" class="head1" width="5%" colspan="6">Datail</th>
</tr>
<?php
$str = !empty($_GET['id'])?" where ceb_id='{$_GET['id']}'":"";
$strSearch = !empty($_GET['txtsearch'])?
" where eb_iddoc like '%{$_GET['txtsearch']}%' or eb_title like '%{$_GET['txtsearch']}%' ":" ";
$sql = " select * from cms_ebook
natural join cms_category_eb
$str $strSearch
order by eb_created desc, eb_order asc";
$result = mysql_query($sql)or die(mysql_error());
$total = mysql_num_rows($result);
$pagesize = 10; // Per Page
$page = 1;
$total_page = ceil($total/$pagesize);
if (isset($_GET[page]))
$page = $_GET[page];
$start = ($page-1)*$pagesize;
$sql .= " limit $start,$pagesize";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
?>
<?
$i = 0;
$i<=$num;
while($row = mysql_fetch_array($result))
{
$color=(@$color=="#ffffff")?"#f0f0f0":"#ffffff";
$i++;
?>
<tr bgcolor="<?php echo $color?>">
<th align="center"><span class="style2"><?php echo $i+$start ?></span></th>
<th align="left"><span class="style2"><?php echo mb_substr($row["eb_iddoc"], 0, 13, 'utf-8'); ?></span></th>
<th align="left"><span class="style2"><?php echo mb_substr($row["eb_title"], 0, 130, 'utf-8'); ?></span></th>
<th align="center"><span class="style2"><?php echo showgroup(showgebook($row["ceb_id"])) ?></span></th>
<th align="center"><span class="style2"><?php echo showcebook($row["ceb_id"]) ?></span></th>
<th align="center"><span class="style2"><?php echo formatshortdate($row["eb_created"]) ?></span></th>
<th align="center"><span class="style2"><?php echo showmember_by($row["eb_created_by"]) ?></span></th>
<th align="center" width="5%">
<a href="<?php echo $filepath = "../../file_ebook/".$row['eb_filename'];?>" target="_blank">Attach</a>
</th>
<th align="center" width="5%">
<a href="detail_published.php?id=<?php echo $row["eb_id"]?>"><img src="../images/icons_backoffice/detail_an.png" width="15" border="0" title="Preview E-Book" /></a>
</th>
<!-- Entry Not Found -->
<?
}
if($num <= 0){
?>
<tr class="comment">
<td height="30" colspan="12" align="center" valign="middle" bgcolor="#FFFFFF">Entry Not Found</td>
</tr>
<!-- Entry Not Found -->
<?
}
?>
</table>
</form>
<br />
<div align="left"><strong>
Page :
<?php for ($i=1; $i<=$total_page; $i++){
if ($i==$page)
echo " $i ";
else
echo " <a href='?page=$i'>$i</a> ";
if ($i!=$total_page)
echo " | ";
}
?>
<br />
Total : <?php echo $total ?> items
</strong><br />
</div>
<tr>
</tr>
</table>
</table>
<!-- /////////////////////////////// From Webpage /////////////////////////////// -->
Tag : PHP, MySQL, HTML/CSS, CakePHP
|
ประวัติการแก้ไข 2012-08-27 09:34:43 2012-08-27 09:51:37
|
|
|
|
|
Date :
2012-08-27 09:33:36 |
By :
nattkhanesha |
View :
912 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ พี่วิน
แล้วถ้าผมจะนำไปใช้กับการค้นหาแบบหลายเงื่อนไขจะต้องใส่โค๊ดแบบไหนครับ
Code (PHP)
<?php
/// GET Data
$txtsearch = $_REQUEST['txtsearch']; // key1
$date1 = $_REQUEST['date3']; // key2
$date2 = $_REQUEST['date4']; // key2
$catid = $_REQUEST['subcategory']; // key5
/// key checkbox
$key1 = $_REQUEST['key1']; // text
$key2 = $_REQUEST['key2']; // date between
$key5 = $_REQUEST['key5']; // category
if(!$key1 && !$key2 && !$key5)
{
$sql = "select * from cms_ebook where eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key1==1 && $key2==1 && $key5==1)
{
$sql = "select * from cms_ebook where (eb_iddoc like '%$txtsearch%' or eb_title like '%$txtsearch%' and date(eb_created) >= '$date1' and date(eb_created) <= '$date2' and ceb_id like '%$catid%') and eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key1==1 && $key2==1)
{
$sql = "select * from cms_ebook where (eb_iddoc like '%$txtsearch%' or eb_title like '%$txtsearch%' and date(eb_created) >= '$date1' and date(eb_created) <= '$date2') and eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key1==1 && $key5==1)
{
$sql = "select * from cms_ebook where (eb_iddoc like '%$txtsearch%' or eb_title like '%$txtsearch%' and ceb_id like '%$catid%') order by eb_created desc, eb_order asc";
}
elseif($key2==1 && $key5==1)
{
$sql = "select * from cms_ebook where (date(eb_created) >= '$date1' and date(eb_created) <= '$date2' and ceb_id like '%$catid%') and eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key1==1)
{
$sql = "select * from cms_ebook where (eb_iddoc like '%$txtsearch%' or eb_title like '%$txtsearch%') and eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key2==1)
{
$sql = "select * from cms_ebook where (date(eb_created) >= '$date1' and date(eb_created) <= '$date2') and eb_active=1 and eb_active=1 order by eb_created desc, eb_order asc";
}
elseif($key5==1)
{
$sql = "select * from cms_ebook where (ceb_id like '%$catid%') and eb_active=1 order by eb_created desc, eb_order asc";
}
$result = mysql_query($sql)or die(mysql_error());
$total = mysql_num_rows($result);
$pagesize = 30; // Per Page
$page = 1;
$total_page = ceil($total/$pagesize);
if (isset($_GET[page]))
$page = $_GET[page];
$start = ($page-1)*$pagesize;
$sql .= " limit $start,$pagesize";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
?>
<?
$i = 0;
$i<=$num;
while($row = mysql_fetch_array($result))
{
$color=(@$color=="#ffffff")?"#f0f0f0":"#ffffff";
$i++;
?>
<tr bgcolor="<?php echo $color?>">
<th align="center"><span class="style2"><?php echo $i+$start ?></span></th>
<th align="left"><span class="style2"><?php echo mb_substr($row["eb_iddoc"], 0, 13, 'utf-8'); ?></span></th>
<th align="left"><span class="style2"><?php echo mb_substr($row["eb_title"], 0, 130, 'utf-8'); ?></span></th>
<th align="center"><span class="style2"><?php echo showgroup(showgebook($row["ceb_id"])) ?></span></th>
<th align="center"><span class="style2"><?php echo showcebook($row["ceb_id"]) ?></span></th>
<th align="center"><span class="style2"><?php echo formatshortdate($row["eb_created"]) ?></span></th>
<th align="center" width="5%">
<!--<a href="<?php echo $filepath = "../../file_ebook/".$row['eb_filename'];?>" target="_blank">Attach</a>-->
<a href="#" onclick="javascript: if(confirm('You want to open the file ???')){window.location='download.php?id=<? echo $row['eb_id']; ?>';}">Attach</a>
</th>
<th align="center" width="5%">
<a href="detail_published.php?id=<?php echo $row["eb_id"]?>"><img src="../images/icons_backoffice/detail_an.png" width="15" border="0" title="Preview E-Book" /></a>
</th>
<!-- Entry Not Found -->
<?
}
if($num <= 0){
?>
<tr class="comment">
<td height="30" colspan="14" align="center" valign="middle" bgcolor="#FFFFFF">Entry Not Found</td>
</tr>
<!-- Entry Not Found -->
<?
}
?>
</table>
</form>
<br />
<div align="left"><strong>
Page :
<?php for ($i=1; $i<=$total_page; $i++){
if ($i==$page)
echo " $i ";
else
echo " <a href='?page=$i'>$i</a> ";
if ($i!=$total_page)
echo " | ";
}
?>
<br />
Total : <?php echo $total ?> items
</strong><br />
|
|
|
|
|
Date :
2012-08-28 08:27:07 |
By :
nattkhanesha |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณก็จะต้องส่งไปทั้งหมดครับ
|
|
|
|
|
Date :
2012-08-28 21:02:05 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|