|
|
|
สอบถามการใส่โค๊ดเข้าไปเพื่อแบ่งหน้า จากข้อมูลที่ค้นหาในดาต้าเบสครับ |
|
|
|
|
|
|
|
โดยปกติโค๊ดชุดนี้เมื่อค้นหาข้อมูลมันจะแสดงหน้าเดียวซึ่งมันเยอะมากครับ
ต้องการที่จะให้มันแสดงข้อมูลต่อหน้าซัก 100หรือ50ก็ได้ครับ จะต้องใช้แบบไหน แล้วเอาไปใส่ตรงไหนครับ
คือปมดูที่มีๆอยู่แล้วยังไม่ค่อยกระจ่าง รบกวนช่วยสอนด้วยครับ ขอบคุณครับ
Code (PHP)
<div align="center">
<form id="form_search" name="form_search" method="post" action="customer_search.php">
<table width="920" border="0" bgcolor="#f3f1eb">
<tr>
<td width="505"></td>
<td width="159">
ค้นหาจาก <label for="cb_serach"></label>
<select name="cb_serach" id="cb_serach">
<option selected="selected">รหัสลูกค้า</option>
<option>ชื่อ </option>
<option>นามสกุล</option>
<option>ชื่อ - นามสกุล</option>
<option>เบอร์โทรศัพท์</option>
<option>รหัสไปรษณีย์</option>
</select></td>
<td width="44">ค้นหา<label for="txt_search"></label></td>
<td width="144"><input type="text" name="txt_search" id="txt_search" /></td>
<td width="46"><input type="submit" name="btn_search" id="btn_search" value="ค้นหา" /></td>
</tr>
</table>
</form>
<?
$text = $_POST["txt_search"];
$listdata = $_POST["cb_serach"];
if(trim($_POST["txt_cus_id"]) != ""){
$listdata = "รหัสลูกค้า";
$text = trim($_POST["txt_cus_id"]);
//$text = "46000267";
}else if(trim($_POST["txt_name_last"]) != ""){
$listdata = "ชื่อ - นามสกุล";
$text = trim($_POST["txt_name_last"]);
}
else if(trim($_POST["txt_name"]) != ""){
$listdata = "ชื่อ";
$text = trim($_POST["txt_name"]);
}
else if(trim($_POST["txt_last"]) != ""){
$listdata = "นามสกุล";
$text = trim($_POST["txt_last"]);
}
else if(trim($_POST["txt_mobile"]) != ""){
$listdata = "เบอร์โทรศัพท์";
$text = trim($_POST["txt_mobile"]);
}
else if(trim($_POST["txt_postalcode"]) != ""){
$listdata = "รหัสไปรษณีย์";
$text = trim($_POST["txt_postalcode"]);
}
else if(trim($_POST["txt_postalcode"]) != ""){
$listdata = "รหัสไปรษณีย์";
$text = trim($_POST["txt_postalcode"]);
}
else if(trim($_POST["txt_serial"]) != ""){
$listdata = "S/N";
$text = trim($_POST["txt_serial"]);
}
if($text != "")
{
$textA = split(' ',$text);
include_once("script/php/connect.php");
include_once("script/php/db_customer.php");
$SQL = "select cus.cus_id,cus.cus_firstname , cus.cus_lastname ,(select provinceName from province where provinceId = cus.cus_province) as province , (select districtName from district where districtId = cus.cus_district) as district , (select amphurName from amphur where amphurId = cus.cus_sub_district) as aumphur, cus_address,cus_postalcode , cus.cus_mobilephone from customer as cus ";
if($listdata == "รหัสลูกค้า"){
$SQL .= " WHERE cus_id LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "ชื่อ"){
$SQL .= " WHERE cus_firstname LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "นามสกุล"){
$SQL .= " WHERE cus_lastname LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "ชื่อ - นามสกุล"){
$SQL .= " WHERE cus_firstname LIKE '%$textA[0]%' or cus_lastname LIKE '%$textA[1]%' order by cus_id asc" ;
}
else if($listdata == "เบอร์โทรศัพท์"){
$SQL .= " WHERE cus_mobilephone LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "รหัสไปรษณีย์"){
$SQL .= " WHERE cus_postalcode LIKE '$text' order by cus_id asc";
}
else if($listdata == "S/N"){
$SQL = "select customer.cus_id,cus_firstname,cus_lastname,cus_mobilephone,cus_address,(select provinceName from province where provinceId = customer.cus_province) as province ,(select districtName from district where districtId = customer.cus_district) as district,(select amphurName from amphur where amphurId = customer.cus_sub_district) as aumphur,cus_postalcode,customer_product.serial_number from customer left join customer_product on customer.cus_id=customer_product.cus_id where serial_number LIKE '%$text%' order by cus_id asc";
}
else{
$SQL .= " where cus_firstname = '$textA[1]' and cus_lastname = '$textA[2]' and cus_id = '$textA[0]' order by cus_id asc";
}
$select = mysql_select_db("crm", connect_db());
$query = mysql_query($SQL);
?>
<table width="920" border="1" cellspacing="0">
<tr bgcolor="#f3f1eb" bordercolor="#00CC99">
<th width="87" align="center"> รหัสลูกค้า </th>
<th width="120" align="center"> ชื่อ - นามสกุล</th>
<th width="50" align="center"> เบอร์ </th>
<th width="150" align="center"> ที่อยู่ </th>
<th width="30" align="center"> ตำบล/แขวง </th>
<th width="30" align="center"> อําเภอ/เขต </th>
<th width="30" align="center"> จังหวัด</th>
<th width="30" align="center">ไปรษณีย์</th>
<?php
if($listdata == "S/N"){
echo "<th width='70' align='center'> S/N </th>";
}
?>
<th width="70" align="center"> แก้ไข</th>
<th width="10" align="center"> ดูข้อมูล</th>
</tr>
<?
while($result = mysql_fetch_array($query))
{
?>
<tr>
<td align="center"><?=$result["cus_id"];?></td>
<td><?=$result["cus_firstname"] . " " . $result["cus_lastname"];?></td>
<td><?=$result["cus_mobilephone"];?></td>
<td align="left"><?=$result["cus_address"];?></td>
<td align="left"><?=$result["district"];?></td>
<td align="left"><?=$result["aumphur"];?></td>
<td align="left"><?=$result["province"];?></td>
<td align="center"><?=$result["cus_postalcode"];?></td>
<?php
if($listdata == "S/N"){
echo "<td align='center'>$result[serial_number]</td>";
}
?>
<td align="center"><a href="customer_edit.php?cus_id=<?=$result["cus_id"]?>">แก้ไข</a></td>
<!--<td align="center"><a href="customer_view.php?cus_id=<?=$result["cus_id"]?>">ดูข้อมูล</a></td>-->
</tr>
<?
}
?>
</table>
<?
}
?>
</div>
Tag : PHP, MySQL, HTML/CSS, Action Script, Windows
|
|
|
|
|
|
Date :
2014-03-13 13:34:08 |
By :
midnightsara |
View :
685 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้ Jquery Tablesorter ครับ
http://tablesorter.com/docs/
|
|
|
|
|
Date :
2014-03-13 15:21:24 |
By :
Berbatov23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แบ่งหน้าได้แล้วครับ แต่พอกดหน้าต่อไปไม่มีข้อมูลครับ ไม่ทราบว่าเป็นที่จุดไหนครับ ขอบคุณครับ
Code (PHP)
<form id="form_search" name="form_search" method="post" action="customer_search.php">
<table width="920" border="0" bgcolor="#f3f1eb">
<tr>
<td width="505"></td>
<td width="159">
ค้นหาจาก <label for="cb_serach"></label>
<select name="cb_serach" id="cb_serach">
<option selected="selected">รหัสลูกค้า</option>
<option>ชื่อ </option>
<option>นามสกุล</option>
<option>ชื่อ - นามสกุล</option>
<option>เบอร์โทรศัพท์</option>
<option>รหัสไปรษณีย์</option>
</select></td>
<td width="44">ค้นหา<label for="txt_search"></label></td>
<td width="144"><input type="text" name="txt_search" id="txt_search" value="<?=$_POST["txt_search"];?>" /> </td>
<td width="46"><input type="submit" name="btn_search" id="btn_search" value="ค้นหา" /></td>
</tr>
</table>
</form>
<?
$text = $_POST["txt_search"];
$listdata = $_POST["cb_serach"];
if(trim($_POST["txt_cus_id"]) != ""){
$listdata = "รหัสลูกค้า";
$text = trim($_POST["txt_cus_id"]);
//$text = "46000267";
}else if(trim($_POST["txt_name_last"]) != ""){
$listdata = "ชื่อ - นามสกุล";
$text = trim($_POST["txt_name_last"]);
}
else if(trim($_POST["txt_name"]) != ""){
$listdata = "ชื่อ";
$text = trim($_POST["txt_name"]);
}
else if(trim($_POST["txt_last"]) != ""){
$listdata = "นามสกุล";
$text = trim($_POST["txt_last"]);
}
else if(trim($_POST["txt_mobile"]) != ""){
$listdata = "เบอร์โทรศัพท์";
$text = trim($_POST["txt_mobile"]);
}
else if(trim($_POST["txt_postalcode"]) != ""){
$listdata = "รหัสไปรษณีย์";
$text = trim($_POST["txt_postalcode"]);
}
else if(trim($_POST["txt_serial"]) != ""){
$listdata = "S/N";
$text = trim($_POST["txt_serial"]);
}
if($text != "")
{
$textA = split(' ',$text);
include_once("script/php/connect.php");
include_once("script/php/db_customer.php");
//$SQL = "SELECT * FROM customer WHERE cus_firstname LIKE '%".$_POST["txt_search"]."%' or cus_lastname LIKE '%".$_POST["txt_search"]."%' or cus_id LIKE '%".$_POST["txt_search"]."%' or cus_mobilephone LIKE '%".$_POST["txt_search"]."%' )" ;
//$query = mysql_query($sql);
//$result = mysql_db_query($select,$sql);
//$result = mysql_num_rows($query);
$SQL = "select cus.cus_id,cus.cus_firstname , cus.cus_lastname ,(select provinceName from elvira_crm.province where provinceId = cus.cus_province) as province , (select districtName from elvira_crm.district where districtId = cus.cus_district) as district , (select amphurName from elvira_crm.amphur where amphurId = cus.cus_sub_district) as aumphur, cus_address,cus_postalcode , cus.cus_mobilephone from elvira_crm.customer as cus ";
if($listdata == "รหัสลูกค้า"){
$SQL .= " WHERE cus_id LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "ชื่อ"){
$SQL .= " WHERE cus_firstname LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "นามสกุล"){
$SQL .= " WHERE cus_lastname LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "ชื่อ - นามสกุล"){
$SQL .= " WHERE cus_firstname LIKE '%$textA[0]%' or cus_lastname LIKE '%$textA[1]%' order by cus_id asc" ;
}
else if($listdata == "เบอร์โทรศัพท์"){
$SQL .= " WHERE cus_mobilephone LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "รหัสไปรษณีย์"){
$SQL .= " WHERE cus_postalcode LIKE '$text' order by cus_id asc";
}
else if($listdata == "S/N"){
$SQL = "select customer.cus_id,cus_firstname,cus_lastname,cus_mobilephone,cus_address,(select provinceName from elvira_crm.province where provinceId = customer.cus_province) as province ,(select districtName from elvira_crm.district where districtId = customer.cus_district) as district,(select amphurName from elvira_crm.amphur where amphurId = customer.cus_sub_district) as aumphur,cus_postalcode,customer_product.serial_number from customer left join customer_product on customer.cus_id=customer_product.cus_id where serial_number LIKE '%$text%' order by cus_id asc";
}
else{
$SQL .= " where cus_firstname = '$textA[1]' and cus_lastname = '$textA[2]' and cus_id = '$textA[0]' order by cus_id asc";
}
$select = mysql_select_db("elvira_crm", connect_db());
$query = mysql_query($SQL);
/* ////////////////////////////////////////////////////////////////////////////// */
$query = mysql_query($SQL) or die ("Error Query [".$SQL."]");
$Num_Rows = mysql_num_rows($query);
$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);
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;
}
$strSQL .=" order by cus_id ASC LIMIT $Page_Start , $Per_Page";
$query = mysql_query($SQL);
?>
<table width="920" border="1" cellspacing="0">
<tr bgcolor="#f3f1eb" bordercolor="#00CC99">
<th width="87" align="center"> รหัสลูกค้า </th>
<th width="120" align="center"> ชื่อ - นามสกุล</th>
<th width="50" align="center"> เบอร์ </th>
<th width="150" align="center"> ที่อยู่ </th>
<th width="30" align="center"> ตำบล/แขวง </th>
<th width="30" align="center"> อําเภอ/เขต </th>
<th width="30" align="center"> จังหวัด</th>
<th width="30" align="center">ไปรษณีย์</th>
<?php
if($listdata == "S/N"){
echo "<th width='70' align='center'> S/N </th>";
}
?>
<th width="70" align="center"> แก้ไข</th>
<th width="10" align="center"> ดูข้อมูล</th>
</tr>
<?
while($result = mysql_fetch_array($query))
{
?>
<tr>
<td align="center"><?=$result["cus_id"];?></td>
<td><?=$result["cus_firstname"] . " " . $result["cus_lastname"];?></td>
<td><?=$result["cus_mobilephone"];?></td>
<td align="left"><?=$result["cus_address"];?></td>
<td align="left"><?=$result["district"];?></td>
<td align="left"><?=$result["aumphur"];?></td>
<td align="left"><?=$result["province"];?></td>
<td align="center"><?=$result["cus_postalcode"];?></td>
<?php
if($listdata == "S/N"){
echo "<td align='center'>$result[serial_number]</td>";
}
?>
<td align="center"><a href="customer_edit.php?cus_id=<?=$result["cus_id"]?>">แก้ไข</a></td>
<!--<td align="center"><a href="customer_view.php?cus_id=<?=$result["cus_id"]?>">ดูข้อมูล</a></td>-->
</tr>
<?
}
?>
</table>
<?
}
?>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[PHP_SELF]?Page=$Prev_Page&txt_search=$_POST[txt_search]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[PHP_SELF]?Page=$i&txt_search=$_POST[txt_search]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[PHP_SELF]?Page=$Next_Page&txt_search=$_POST[txt_search]'>Next>></a> ";
}
mysql_close($objConnect);
?>
|
|
|
|
|
Date :
2014-03-14 11:33:26 |
By :
midnightsara |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|