 |
โค๊ดแบ่งหน้า PHP+MySQL แก้ไขดัดแปลงและทดลองใช้งานโดย PlaKriM |
|
 |
|
|
 |
 |
|
จากกระทู้นี้ ปล่อยของหรือปล่อยไก่
ผมลืมไปว่าโค๊ดตัวล่าสุดผมไม่ได้เป็นเยี่ยงนั้น ทำให้ต้องมาโพสต์แก้ไข เพื่อให้น้องๆ ที่เพิ่งหัดเขียนได้นำไปปรัปใช้กัน
โดยโค๊ดที่ผมใช้อยู่นี้ได้ดัดแปลงจากโค๊ด pu_split ของคุณพีกับยู (มั้ง) ลอง search หาดูก็น่าจะเจอเพิ่งคิดออกว่าเอาโค๊ดมาจากไหน อย่าเสียเวลามาดู โค๊ดกัน
Function
Code (PHP)
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
?>
ตัวอย่างการใช้งาน
Code (PHP)
<?php
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE category_id = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM product" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $connection_id);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $connection_id));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["product_name"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
บางท่านอาจสงสัยว่า ทำไมมันเปลี่ยนโค๊ดบ่อยจังวะ บอกได้เลยว่ามันพัฒนาตามประสบการณ์ และเพื่อให้เหมาะกับงานแต่ละงานครับ
จบข่าว.....แปะแล้วชิ่ง.....
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-03-30 21:33:44 |
By :
plakrim |
View :
25347 |
Reply :
170 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากคับ เด๋วจะเอาไปลองทำดู
|
 |
 |
 |
 |
Date :
2009-03-30 21:42:21 |
By :
mai_sao |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$connection_id ถูกหรือเปล่าครับ
$connection_id = mysql_connect อะครับ ใครไม่สันทัดตัดออกไปได้เลย
|
 |
 |
 |
 |
Date :
2009-03-31 00:06:52 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามมาคอนเฟิร์มว่าโค้ดนี้ใช้ได้ครับ เพราะใช้ไปแล้ว 1 งาน อิอิอิ 
ใช้ได้ครับ คอนเฟิร์ม (ต้องอ่านเสียงดังๆนะครับบรรทัดนี้ อิอิอิ)
|
 |
 |
 |
 |
Date :
2009-03-31 00:43:24 |
By :
zepherus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แน่นอนครับ ถ้าใช้ไม่ได้ผมจะเอามาแปะทำไก่กุ๊กๆ หรอครับ 
|
 |
 |
 |
 |
Date :
2009-03-31 01:11:21 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียน พี่ PlaKriM
ผมขอส่งโค๊ดมาให้พี่ดูละกัน ผมตั้งแก้มาหลายชั่วโมงแล้ว หาที่ error ไม่เจอเลยครับ
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $target= อันนี้รู้ๆ กัน
# $current_style = css สำหรับ navi
# $quetystring= ส่งตัวแปรอะไรไปด้วย
#######################################################################
function page_navi($page, $limit, $range, $count, $target="_self", $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<?php
$hostNameDB = "localhost";
$userNameDB = "user";
$passWordDB = "user";
//$conn = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
$conn = mysql_connect($hostNameDB, $userNameDB, $passWordDB) or die ("Cannot connect to Server or connect db_cmpdurable Database");
mysql_query("SET NAMES tis620", $conn);
mysql_query("USE db_listmenu");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 50;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE username_id = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM tb_username". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $connection_id);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $connection_id));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["firstname"];
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-03-31 01:18:46 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
replace $connection_id ด้วย $conn ครับ แค่นี้ก็น่าจะได้แล้ว
|
 |
 |
 |
 |
Date :
2009-03-31 02:01:05 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียน พี่ PlaKriM ครับ
ขอขอบคุณมากครับ ผมแสดงผลได้แล้วครับ หา error อยู่นานเลย แต่คิดว่าจะอยู่ตรงตัวแปร
$conn นี่เองครับ...
|
 |
 |
 |
 |
Date :
2009-03-31 09:23:31 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียน พี่ PlaKriM ค่ะ
รบกวนด้วยนะค่ะ หากต้องการจะแสดงผลให้เป็นรูปแบบ
[size=6 pt]total : zz record | xx/zz < < 5 > > [/size]
จะต้องแก้ไขโค๊ดของพี่อย่างไรค่ะ และหนูก็ทำมาหลายชั่วโมงแล้วก็ไม่ตรงที่ต้องการเลย
ขอขอบคุณมากค่ะ......
|
 |
 |
 |
 |
Date :
2009-03-31 09:31:19 |
By :
LukNam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
xx คืออะไรครับ
|
 |
 |
 |
 |
Date :
2009-03-31 10:35:50 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
total : zz record | xx/zz < < 5 > >
zz คือหน้าทั้งหมด
xx คือหน้าที่แสดงอยู่ขณะนั้น
zz คือหน้าทั้งหมด (เหมือนกับตัวแรก)
หมายเลข 5 คือแสดงหน้าอยู่ขณะนั้น
ส่วนลูกศร จะเหมือนโค๊ดที่พี่เขียนนั่นแหละค่ะ
ขอขอบคุณมาก ๆ เลยนะค่ะ
--------------------------------------
อีกเรื่อง หากอยากเอาโค๊ดการแบ่งหน้านี้มาประยุกต์ใช้กับการค้นหา จะต้องเขียนเพื่ออย่างไรค่ะ
นั่งเขียนมาหลายชั่วโมงแล้ว ตั้งแต่เมื่อวานเย็น ...ขอขอบคุณค่ะ..
|
 |
 |
 |
 |
Date :
2009-03-31 10:52:13 |
By :
LukNam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ายังไงคืนนี้เดี๋ยวจะเขียนตัวอย่างการค้นหาให้ดูนะครับ ไม่ยาก
|
 |
 |
 |
 |
Date :
2009-03-31 10:54:31 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ ลูกน้ำตัวน้อย
นี่สำหรับ rep no. 11 นะครับ
Code (PHP)
<?php
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$sql = "SELECT * FROM tb_user";
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $conn);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $conn));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows['username']."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 0, $total) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
นี่สำหรับ ค้นหา แค่ใส่ชื่อ textSearch เข้าไป แล้วใช้ LIKE
Code (PHP)
<?php
if(isset($_GET["textSearch"]) and $_GET["textSearch"] != ""){
$send = "textSearch=" . $_GET["textSearch"];
$condition= " WHERE username LIKE '%" . $_GET["textSearch"] . "%'";
}
?>
ลองดูครับ ผมไม่เขียนให้หมดหรอก แต่แค่นี้ก็น่าจะไปได้แล้ว หวังว่าคงเข้าใจนะ
ส่วนที่ว่าจะค้นหาด้วย dropdownlist นั้นไม่ต้องแบ่งหน้ามั้ง แค่ใช้
<select name="user_id" onchange="location.herf='?user_id=' + this.value;">
ตรงนี้ select ชื่อ user มา เช่น <option value="<? echo $user_id; ?>"><? echo $username; ?></option>
</select>
แล้วก็ รับ user_id ด้วย
$user_id = $_GET["user_id"]
และ select * from tb_user where user_id = '$user_id'
แบบนี้หวังว่าจะเข้าใจและดัดแปลงไปใช้งานได้นะครับ
|
 |
 |
 |
 |
Date :
2009-03-31 20:26:46 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำลืมแก้ นี่ตรง total : zz record | xx/zz < < 5 > > นะครับ
Code (PHP)
<?php
echo "\n<div style=\"float:left;\">total : " . $total ." record | " . $page ."/" . $total ." " . page_navi($page, $limit_end, 0, $total, $send) . "</div>";
?>
|
 |
 |
 |
 |
Date :
2009-03-31 20:30:03 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไปช่วยกันตอบกระทู้ และแก้ปัญหา
https://www.thaicreate.com/php/forum/025934.html
ด้วยนะครับ
อยากได้หลายคนเลยครับ...
เรียนพี่ PlaKriM ช่วยไปเอาโค๊ดแบ่งหน้าของพี่ ไปแก้ไขให้ด้วยนะครับ
ผมอยากได้นะครับ และมีผู้เดือดร้อน รอความหวังอยู่นะครับ...
ขอขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2009-03-31 21:51:57 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่เขาสุดยอดจริงจริงครับ
|
 |
 |
 |
 |
Date :
2009-03-31 22:39:34 |
By :
mosaddzero |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดให้ หน้า AjaxPHPSearchRecordPaging1 แก้ตรงนี้ <body Onload="JavaScript:doCallAjax('','1');">
ส่วนนี่โค๊ดหน้า 2
Code (PHP)
<?php
function page_navi($page, $limit, $range, $count){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $page . "');\" ><strong>«</strong></a> ";
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $navi_back . "');\" ><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $i . "');\" ><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $i . "');\" >$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $navi_next . "');\" ><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $total . "');\" ><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $page . "');\" ><strong>$page</strong></a> ";
return $output;
}
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost:3308","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("test");
$page = (isset($_POST['page']))? intval($_POST['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
if(isset($_POST["mySearch"]) and $_POST["mySearch"] != ""){
$condition= " Name LIKE '%" . $_POST["mySearch"] ."%'";
}
$sql = "SELECT * FROM customer " . $condition;
echo $sql . " LIMIT " . $limit_start. "," . $limit_end;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID</div></th>
<th width="98"> <div align="center">Name</div></th>
<th width="198"> <div align="center">Email</div></th>
<th width="97"> <div align="center">CountryCode</div></th>
<th width="59"> <div align="center">Budget</div></th>
<th width="71"> <div align="center">Used</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($query_id))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<br>
<?
echo page_navi($page, $limit_end, 4, $total);
mysql_close($objConnect);
?>
|
 |
 |
 |
 |
Date :
2009-03-31 23:41:42 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ PlaKriM มากนะค่ะ
ที่ช่วยแก้ไขการแสดงหน้าแบบ
total : zz record | xx/zz < < 5 > >
-------------------------------------
|
 |
 |
 |
 |
Date :
2009-04-01 01:41:21 |
By :
LukNam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ PlaKriM ครับ
Code ที่พี่แก้ไขให้ AjaxPHPSearchRecordPaging
ไม่เห็นว่าจะค้นหาข้อมูลได้ และก็กดปุ่ม next ไม่ได้เลยนะครับ
จาก Code ที่ no.20 นะครับ...
--------------------------------------------------------------------
|
 |
 |
 |
 |
Date :
2009-04-01 08:56:20 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของผมแสดงข้อมูลน่ะคับ แต่กด next ไปไม่ได้ error แบบนี้
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\chob\show_test.php on line 55
|
 |
 |
 |
 |
Date :
2009-04-01 10:33:13 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฟอร์มน่ะครับ
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=2 bgcolor="#F5FFFA">
<FORM action="show_test.php" method="post" target="_blank" name="frm" onSubmit="return checkform(frm)">
<TBODY>
<TR>
<TD><div align="center" class="fixtext4">
<h1><span class="menulink">ค้นหา หอพัก, ห้องเช่า, อพาร์ทเมนท์,
ห้องพัก, คอนโด, ที่พัก</span></h1>
</div></TD>
</TR>
<TR>
<TD><div align="center"></div></TD>
</TR>
<TR>
<TD align="center"><span class="menulink">ค้นหาด้วยคำค้น </span>
<SELECT name=sta>
<option value="">-- เลือกรายการ--</option>
<option value="horpak_name">ชื่อหอพัก</option>
<option value="min_price">ราคาต่ำสุด</option>
<option value="max_price">ราคาสูงสุด</option>
<option value="h_klang">ราคากลาง</option>
<option value="horpak_road">ถนน</option>
<option value="horpak_tumboon">ตำบล/แขวง</option>
<option value="horpak_maung">อำเภอ</option>
<option value="horpak_zone">เขต</option>
<option value="province">จังหวัด</option>
<option value="university">มหาวิทยาลัยใกล้เคียง</option>
</SELECT> <input name="detail" type="text" size="30">
<input name="submit" type="submit" id="submit" value="ค้นหา"> </TD>
</TR>
<TR>
<TD align="center"> </TD>
</TR>
</TBODY>
</FORM>
</TABLE>
####################################ฐานข้อมูล
-- phpMyAdmin SQL Dump
-- version 2.10.2
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง: 01 เม.ย. 2009 น.
-- รุ่นของเซิร์ฟเวอร์: 5.0.45
-- รุ่นของ PHP: 5.2.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `horpak`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `ads`
--
CREATE TABLE `ads` (
`id_ads` int(10) NOT NULL auto_increment,
`own_name` varchar(50) NOT NULL,
`own_tel` varchar(12) NOT NULL,
`own_email` varchar(50) NOT NULL,
`horpak_name` varchar(100) NOT NULL,
`horpak_type` varchar(100) NOT NULL,
`room_type` varchar(100) NOT NULL,
`min_price` varchar(20) NOT NULL,
`max_price` varchar(20) NOT NULL,
`h_prakan` varchar(20) NOT NULL,
`h_klang` varchar(20) NOT NULL,
`h_water` varchar(20) NOT NULL,
`h_elect` varchar(20) NOT NULL,
`ubc` varchar(5) NOT NULL,
`tel` varchar(5) NOT NULL,
`furniture` varchar(5) NOT NULL,
`air` varchar(5) NOT NULL,
`bath` varchar(5) NOT NULL,
`internet` varchar(5) NOT NULL,
`sak_pa` varchar(5) NOT NULL,
`bts` varchar(5) NOT NULL,
`mrt` varchar(5) NOT NULL,
`jod_rod` varchar(5) NOT NULL,
`pad_lom` varchar(5) NOT NULL,
`police` varchar(5) NOT NULL,
`tv` varchar(5) NOT NULL,
`fitnet` varchar(5) NOT NULL,
`swim` varchar(5) NOT NULL,
`key_card` varchar(5) NOT NULL,
`yod_ren` varchar(5) NOT NULL,
`vong_jorn_pid` varchar(5) NOT NULL,
`minimart` varchar(5) NOT NULL,
`university` varchar(50) NOT NULL,
`horpak_no` varchar(40) NOT NULL,
`horpak_soi` varchar(50) NOT NULL,
`horpak_road` varchar(50) NOT NULL,
`horpak_tumboon` varchar(50) NOT NULL,
`horpak_zone` varchar(50) NOT NULL,
`horpak_maung` varchar(50) NOT NULL,
`province` varchar(50) NOT NULL,
`zip` varchar(6) NOT NULL,
`horpak_tel` varchar(12) NOT NULL,
`horpak_fax` varchar(12) NOT NULL,
`horpak_website` varchar(100) NOT NULL,
`horpak_detail` text NOT NULL,
`pic1` varchar(20) NOT NULL,
`pic2` varchar(20) NOT NULL,
`pic3` varchar(20) NOT NULL,
`pic4` varchar(20) NOT NULL,
`pic5` varchar(20) NOT NULL,
`pic6` varchar(20) NOT NULL,
`son_jai` varchar(20) NOT NULL,
`status` varchar(5) NOT NULL,
`id_member` varchar(20) NOT NULL,
PRIMARY KEY (`id_ads`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
--
-- dump ตาราง `ads`
--
INSERT INTO `ads` VALUES (1, 'สมศรี สมหมาย', '089564231', '[email protected]', 'ราชนาวี', 'อพาร์ทเมนท์', 'เช่ารายเดือน', '3000', '6000', '2000', '4500', '18', '10', '1', '1', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', 'จุฬาลงกรณ์มหาวิทยาลัย', '434', 'ซอยซอย', 'เจริญกรุง', 'เจริญกรุง', 'คลองสาน', 'ยานนาวา', 'กรุงเทพมหานคร', '31000', '086594587', '028564789', 'http://', 'รายละเอียด', '680.jpg', 'hostel021.gif', 'hostel021.gif', 'hostel021.gif', 'hostel021.gif', 'hostel021.gif', 'member', '0', '1');
INSERT INTO `ads` VALUES (2, 'สมชาย สมชาติ1', '08546214361', '[email protected]', 'หอพักราช', 'หอพัก', 'เช่ารายเดือน', '2500', '5000', '1000', '2000', '12', '10', '1', '1', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'ม.เกริก', '1234', 'จิระ', 'จิระ', 'ในเมือง', 'ห้วยขวาง', 'เมือง', 'บุรีรัมย์', '31160', '0132654789', '0123456797', 'http://www.topsiam.com', 'ggggggggggggggggggggggggg\r\nggggggggggggggggggggggggg\r\nggggggggggggggggggggggggg', 'recommend005.jpg', 'recommend005.jpg', 'recommend005.jpg', 'recommend005.jpg', 'recommend005.jpg', 'recommend005.jpg', 'free', '0', '2');
INSERT INTO `ads` VALUES (6, 'สมศรี สมหมาย55', '08956423155', '[email protected]', '6', 'แมนชั่น', 'ขายขาด', '6', '6', '6', '6', '6', '6', '1', '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', 'ม.กรุงเทพ กล้วยน้ำไท', '6', '6', '6', '6', 'ดุสิต', '6', 'กรุงเทพมหานคร', '6', '6', '6', '6', '6', 'Picture1.jpg', 'Picture1.jpg', 'Picture1.jpg', 'Picture1.jpg', 'Picture1.jpg', 'Picture1.jpg', 'free', '0', '1');
################################### CODE แบ่งหน้าแสดงข้อมูล
Code (PHP)
<?php
$sta=$_POST["sta"];
$detail=$_POST["detail"];
include 'connect.php';
mysql_query('SET NAMES UTF8');
$sql="SELECT *FROM `ads` WHERE $sta LIKE '%$detail%'";
$res=mysql_db_query($dbname,$sql);
$check=mysql_num_rows($res);
if($check==0)
{
echo "<font class=\"menulink\"><center>ไม่พบข้อมูล</center>";
}
else
{
/*###################################################################################*/
function page_navi($page, $limit, $range, $count, $target="_self", $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["detail"]) and $_GET["detail"] != ""){
$send = "detail=" . $_GET["detail"];
$condition= " WHERE $sta LIKE '%" . $_GET["detail"] . "%'";
}
$sql1 = "SELECT * FROM ads". $condition;
$query_id = mysql_query($sql1 . " LIMIT " . $limit_start. "," . $limit_end );
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql1));
if($total > 0){
/*##################################################################################*/
while($result=mysql_fetch_array($query_id))
{
$id=$result[id_ads];
$own_name=$result[own_name];
$own_tel=$result[own_tel];
$own_email=$result[own_email];
$min_price=$result[min_price];
$max_price=$result[max_price];
$horpak_name=$result[horpak_name];
$horpak_road=$result[horpak_road];
$horpak_tumboon=$result[horpak_tumboon];
$horpak_maung=$result[horpak_maung];
$horpak_zone=$result[horpak_zone];
$horpak_one=$result[horpak_one];
$province=$result[proviunce];
$univesity=$result[univesity];
$horpak_no=$reult[hopak_no];
$room_type=$result[room_type];
$horpak_type=$result[horpak_type];
$zip=$result[zip];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$internet=$result[internet];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$ubc=$result[ubc];
$tel=$result[tel];
$bath=$result[bath];
$internet=$result[internet];
$sak_pa=$result[sakpa];
$bts=$result[bts];
$mrt=$result[mrt];
$internet=$result[internet];
$status=$result[status];
if($status==1)
{
$status="1";
$status="ไม่ว่าง";
}
else
{
$status="0";
$status="<font class=menulink>ว่าง</font>";
}
?>
<br />
<table width="95%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr valign="top">
ชื่อหอพัก : <font class="menumanage"> <a href="show_detail_all.php?id=<?=$result[id_ads]?>"><?=$result[horpak_name]?></a> <img src="pic/new_05.gif" border="0"> <?=$status?></font><br>
ราคา: <font class="menulink"><?=$result[min_price]?>-<?=$result[max_price]?> </font><br>
ประเภท: <font class="menudelete"><?=$result[horpak_type]?></font><br>
ที่อยู่: <font class="menumanage"> เลขที่<?=$result[horpak_no]?>ถนน.<?=$result[horpak_road]?> เขต.<?=$horpak_zone?> ต.<?=$result[horpak_tumboon]?> อ.<?=$result[horpak_maung]?> จ.<?=$result[province]?> <?=$result[zip]?></font><br><br>
<?
$atec="pic/air".$air.".gif";
$fur="pic/furniture".$furniture.".gif";
$ubc="pic/ubc".$ubc.".gif";
$tel="pic/tel".$tel.".gif";
$bath="pic/bath".$bath.".gif";
$internet="pic/internet".$internet.".gif";
$bts="pic/bts".$bts.".gif";
$mrt="pic/mrt".$mrt.".gif";
?>
<img src="<?=$atec?>"> <img src="<?=$fur?>"> <img src="<?=$ubc?>"> <img src="<?=$tel?>"> <img src="<?=$bath?>"> <img src="<?=$internet?>"> <img src="<?=$bts?>"> <img src="<?=$mrt?>"> <br>
<hr>
<td width="75%" >
</td>
</tr>
</table>
<?
} }
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
<?
mysql_close();
?>
|
 |
 |
 |
 |
Date :
2009-04-01 11:17:24 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$sta=$_REQUEST["sta"];
$detail=$_REQUEST["detail"];
|
 |
 |
 |
 |
Date :
2009-04-01 12:26:50 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือว่าผมอยากจะให้แสดงเฉพาะเงื่อนไขที่ค้นหาน่ะครับ แต่ว่าอันนี้แสดงข้อมูลมาทะงหมดเลยอ่ะคับ เราจะมีวิธีแก้ยังงัยคับ
|
 |
 |
 |
 |
Date :
2009-04-01 13:06:07 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$sql="SELECT *FROM `ads` WHERE $sta LIKE '%$detail%'". $condition;
ผมลองใส่แบบนี้ก้ตรงตามเงือ่นไขน่ะครับแต่ว่ากดน้าต่อไปแล้ว เป็นแบบนี้อีกครับ ผมไม่รู้จะทำยังแล้วครับ ช่วยผมด้วยน่ะครับพี่ๆผู้รู้    
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\chob\show_test.php on line 107
|
 |
 |
 |
 |
Date :
2009-04-01 13:30:14 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
<?php
$sta=$_REQUEST["sta"];
$detail=$_REQUEST["detail"];
include 'connect.php';
mysql_query('SET NAMES UTF8');
$sql="SELECT *FROM `ads` WHERE $sta LIKE '%$detail%'";
$res=mysql_db_query($dbname,$sql);
$check=mysql_num_rows($res);
if($check==0)
{
echo "<font class=\"menulink\"><center>ไม่พบข้อมูล</center>";
}
else
{
/*###################################################################################*/
function page_navi($page, $limit, $range, $count, $target="_self", $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
$page = (isset($_REQUEST['page']))? intval($_REQUEST['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "";
if($detail != "" and $sta != ""){
$send = "sta=" . $sta . "&detail=" . $detail;
$condition= " WHERE " . $sta . " LIKE '%" . $detail . "%'";
}
$sql1 = "SELECT * FROM ads". $condition;
$query_id = mysql_query($sql1 . " LIMIT " . $limit_start. "," . $limit_end );
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql1));
if($total > 0){
/*##################################################################################*/
while($result=mysql_fetch_array($query_id))
{
$id=$result[id_ads];
$own_name=$result[own_name];
$own_tel=$result[own_tel];
$own_email=$result[own_email];
$min_price=$result[min_price];
$max_price=$result[max_price];
$horpak_name=$result[horpak_name];
$horpak_road=$result[horpak_road];
$horpak_tumboon=$result[horpak_tumboon];
$horpak_maung=$result[horpak_maung];
$horpak_zone=$result[horpak_zone];
$horpak_one=$result[horpak_one];
$province=$result[proviunce];
$univesity=$result[univesity];
$horpak_no=$reult[hopak_no];
$room_type=$result[room_type];
$horpak_type=$result[horpak_type];
$zip=$result[zip];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$internet=$result[internet];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$ubc=$result[ubc];
$tel=$result[tel];
$bath=$result[bath];
$internet=$result[internet];
$sak_pa=$result[sakpa];
$bts=$result[bts];
$mrt=$result[mrt];
$internet=$result[internet];
$status=$result[status];
if($status==1)
{
$status="1";
$status="ไม่ว่าง";
}
else
{
$status="0";
$status="<font class=menulink>ว่าง</font>";
}
?>
<table width="95%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr valign="top">
ชื่อหอพัก : <font class="menumanage"> <a href="show_detail_all.php?id=<?=$result[id_ads]?>"><?=$result[horpak_name]?></a> <img src="pic/new_05.gif" border="0"> <?=$status?></font><br>
ราคา: <font class="menulink"> <?=$result[min_price]?>-<?=$result[max_price]?></font><br>
ประเภท: <font class="menudelete"> <?=$result[horpak_type]?></font><br>
ที่อยู่: <font class="menumanage"> เลขที่<?=$result[horpak_no]?> ถนน.<?=$result[horpak_road]?> เขต. <?=$horpak_zone?> ต.<?=$result[horpak_tumboon]?> อ. <?=$result[horpak_maung]?> จ.<?=$result[province]?> <?=$result[zip]?></font><br><br>
<?
$atec="pic/air".$air.".gif";
$fur="pic/furniture".$furniture.".gif";
$ubc="pic/ubc".$ubc.".gif";
$tel="pic/tel".$tel.".gif";
$bath="pic/bath".$bath.".gif";
$internet="pic/internet".$internet.".gif";
$bts="pic/bts".$bts.".gif";
$mrt="pic/mrt".$mrt.".gif";
?>
<img src="<?=$atec?>"> <img src="<?=$fur?>"> <img src="<?=$ubc?>"> <img src="<?=$tel?>"> <img src="<?=$bath?>"> <img src="<?=$internet?>"> <img src="<?=$bts?>"> <img src="<?=$mrt?>"> <br>
<hr>
<td width="75%" >
</td>
</tr>
</table>
<?
} }
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
<?
mysql_close();
?>
?>
ลองดูนะครับ แบบนี้ได้ไหม ถ้าได้แล้ว สังเกตุและทำความเข้าใจนิดหนึ่ง เรื่อง GET POST REQUEST
|
 |
 |
 |
 |
Date :
2009-04-01 13:52:17 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองสั่ง print $sql="SELECT *FROM `ads` WHERE $sta LIKE '%$detail%'". $condition;
ลองกดหน้าถัดไปจะเป็น SELECT *FROM `ads` WHERE LIKE '%%' ไม่ส่งค่าตัวแปรมาเลยทำยังไงคับ
|
 |
 |
 |
 |
Date :
2009-04-01 13:53:18 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กดหน้าต่อไปไม่ได้เลยครับท่านเป็น แบบนี้ ตลอดเลย Warning: mysql_num_rows(): supplied argument is not a valid MySQL
|
 |
 |
 |
 |
Date :
2009-04-01 14:19:37 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
SELECT *FROM เคาะวรรคนิดนึงครับ ดูโค๊ดด้วยครับ
$sql="SELECT *FROM `ads` WHERE $sta LIKE '%$detail%'". $condition; ไม่ต้องนะครับ
เอาที่ผมเขียนให้ดูด้านบนอะครับ $sql="SELECT * FROM `ads` ". $condition;
|
 |
 |
 |
 |
Date :
2009-04-01 14:46:51 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นั่นแหละคับพี่คับ ก้ยังไม่ได้เลยคับ ผมเศร้ามากเลยตอนนี้ทำไมเกิดมาโง่ขนาดนี้ก้ไม่รู้
|
 |
 |
 |
 |
Date :
2009-04-01 15:06:39 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$sta=$_REQUEST["sta"];
$detail=$_REQUEST["detail"];
include 'connect.php';
mysql_query('SET NAMES UTF8');
print $sql1="SELECT * FROM `ads` WHERE $sta LIKE '%$detail%'";
$res=mysql_db_query($dbname,$sql1);
$check=mysql_num_rows($res);
if($check==0)
{
echo "<font class=\"menulink\"><center>ไม่พบข้อมูล</center>";
}
else
{
/*###################################################################################*/
function page_navi($page, $limit, $range, $count, $target="_self", $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total&sta=$sta&detail=$detail" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
$page = (isset($_REQUEST['page']))? intval($_REQUEST['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "";
if($detail != "" and $sta != ""){
$send = "sta=" . $sta . "&detail=" . $detail;
$condition= " WHERE " . $sta . " LIKE '%" . $detail . "%'";
}
print $sql = "SELECT * FROM ads". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end );
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
/*##################################################################################*/
while($result=mysql_fetch_array($query_id))
{
$id=$result[id_ads];
$own_name=$result[own_name];
$own_tel=$result[own_tel];
$own_email=$result[own_email];
$min_price=$result[min_price];
$max_price=$result[max_price];
$horpak_name=$result[horpak_name];
$horpak_road=$result[horpak_road];
$horpak_tumboon=$result[horpak_tumboon];
$horpak_maung=$result[horpak_maung];
$horpak_zone=$result[horpak_zone];
$horpak_one=$result[horpak_one];
$province=$result[province];
$univesity=$result[univesity];
$horpak_no=$reult[hopak_no];
$room_type=$result[room_type];
$horpak_type=$result[horpak_type];
$zip=$result[zip];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$internet=$result[internet];
$air=$result[air];
$furniture=$result[furniture];
$horpak_website=$result[horpak_website];
$h_prakan=$result[h_prakan];
$h_klang=$result[h_klang];
$pic1=$result[pic1];
$ubc=$result[ubc];
$tel=$result[tel];
$bath=$result[bath];
$internet=$result[internet];
$sak_pa=$result[sakpa];
$bts=$result[bts];
$mrt=$result[mrt];
$internet=$result[internet];
$status=$result[status];
if($status==1)
{
$status="1";
$status="ไม่ว่าง";
}
else
{
$status="0";
$status="<font class=menulink>ว่าง</font>";
}
?>
<table width="95%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr valign="top">
ชื่อหอพัก : <font class="menumanage"><a href="show_detail_all.php?id=<?=$result[id_ads]?>"><?=$result[horpak_name]?></a> <img src="pic/new_05.gif" border="0"> <?=$status?></font><br>
ราคา: <font class="menulink"><?=$result[min_price]?>-<?=$result[max_price]?></font><br>
ประเภท: <font class="menudelete"><?=$result[horpak_type]?></font><br>
ที่อยู่: <font class="menumanage"> เลขที่<?=$result[horpak_no]?>ถนน.<?=$result[horpak_road]?> เขต.<?=$horpak_zone?> ต.<?=$result[horpak_tumboon]?> อ.<?=$result[horpak_maung]?> จ.<?=$result[province]?> <?=$result[zip]?></font><br><br>
<?
$atec="pic/air".$air.".gif";
$fur="pic/furniture".$furniture.".gif";
$ubc="pic/ubc".$ubc.".gif";
$tel="pic/tel".$tel.".gif";
$bath="pic/bath".$bath.".gif";
$internet="pic/internet".$internet.".gif";
$bts="pic/bts".$bts.".gif";
$mrt="pic/mrt".$mrt.".gif";
?>
<img src="<?=$atec?>"> <img src="<?=$fur?>"> <img src="<?=$ubc?>"> <img src="<?=$tel?>"> <img src="<?=$bath?>"> <img src="<?=$internet?>"> <img src="<?=$bts?>"> <img src="<?=$mrt?>"> <br>
<hr>
<td width="75%" >
</td>
</tr>
</table>
<?
} }
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, "current_page","other_page",$send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
<?
mysql_close();
?>
|
 |
 |
 |
 |
Date :
2009-04-01 15:08:58 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมเวลากดหน้าต่อๆไป error แบบนี้ตลอดเลย
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ.....
|
 |
 |
 |
 |
Date :
2009-04-01 15:11:03 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดี๋ยวเย็นนี้จะเขียนตัวอย่างให้ดูนะครับ
|
 |
 |
 |
 |
Date :
2009-04-01 17:26:48 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ PUKMTEC C:\AppServ\www\chob\show_test.php on line 55 คืออะไรครับขอดูบรรทัดนี้ด้วย
โค๊ดที่ผมให้ไป ผมโหลดของพี่วินมาแล้วแก้ไข ทดสอบแล้วไม่มีปัญหาอะไรค้นหาได้ กดได้ทุกอัน ผมว่าคุณแก้ผิดตรงไหนหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2009-04-01 22:16:36 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<form name="myfrm" method="get" action="result.php">
<select name="sta" id="sta">
<option value="">-- เลือกรายการ--</option>
<option value="horpak_name">ชื่อหอพัก</option>
<option value="min_price">ราคาต่ำสุด</option>
<option value="max_price">ราคาสูงสุด</option>
<option value="h_klang">ราคากลาง</option>
<option value="horpak_road">ถนน</option>
<option value="horpak_tumboon">ตำบล/แขวง</option>
<option value="horpak_maung">อำเภอ</option>
<option value="horpak_zone">เขต</option>
<option value="province">จังหวัด</option>
<option value="university">มหาวิทยาลัยใกล้เคียง</option>
</select>
<input type="text" name="detail" id="detail" />
<input type="submit" name="button" id="button" value="Submit" />
</form>
result.php
Code (PHP)
<?php
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">" . $i . "</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
mysql_connect("localhost:3308", "root", "root") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
mysql_query("set character_set_results = utf8") or die(mysql_error());
mysql_query("set names utf8") or die(mysql_error());
$sta=$_REQUEST["sta"];
$detail=$_REQUEST["detail"];
$page = (isset($_REQUEST['page']))? intval($_REQUEST['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "";
if($detail != "" and $sta != ""){
$send = "sta=" . $sta . "&detail=" . $detail;
$condition= " WHERE " . $sta . " LIKE '%" . $detail . "%'";
}
$sql = "SELECT * FROM ads". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end );
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
while($result=mysql_fetch_array($query_id)){
echo $result["horpak_name"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}else{
echo "ไม่มีอะไรในกอไผ่";
}
?>
อย่าบอกว่ามันไม่ได้ ผมลงทุนเขียนและเทสแล้ว นอกจากคุณจะแก้โค๊ดผิดเท่านั้นเอง
|
 |
 |
 |
 |
Date :
2009-04-01 22:57:02 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้วขอบคุณมากๆเลยครับพี่เก่งจังเลยทำไมพี่คิดได้เก่งจัง ขอฝากเนื้อฝากตัวเป็นศิษย์อีกคนน่ะครับ อาจารย์
|
 |
 |
 |
 |
Date :
2009-04-01 23:49:44 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาอีกแล้วครับท่าน ผอดีโค๊ดค้นหาของผมมีหลายเงื่อนไขอ่ะครับพี่ อย่างเช่นน่ะคับ
Code (PHP)
<?php
$horpak_zone=$_REQUEST["horpak_zone"];
$type_zone=$_REQUEST["type_zone"];
$price_zone = array('','<2000','BETWEEN 2001 AND 2999','BETWEEN 3001 AND 3999','BETWEEN 4001 AND 4999','>5000');
$price = $price_zone[$_REQUEST[price_zone]];
$page = (isset($_REQUEST['page']))? intval($_REQUEST['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "";
if($horpak_zone != "" and $type_zone != "" and $price !=""){
$send = "horpak_zone=" . $horpak_zone . "&type_zone=" . $type_zone."&price=" .$price;
$condition= " WHERE horpak_zone = '$horpak_zone ' AND horpak_type= '$type_zone' OR min_price $price OR max_price $price OR h_klang $price ";
}
else
{
$send = "horpak_zone=" . $horpak_zone . "&type_zone=" . $type_zone."&price=" .$price;
$condition= " WHERE horpak_zone = '$horpak_zone ' AND horpak_type= '$type_zone' OR min_price $price OR max_price $price OR h_klang $price ";
}
?>
ผมจะสามารถเช็คเงื่อนไขของผมได้อย่างไรอ่ะคับ รบกวนด้วยน่ะครับ
|
 |
 |
 |
 |
Date :
2009-04-02 09:04:02 |
By :
ningning |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียน พี่ PlaKriM ครับ
จาก no. 36 ที่พี่เขียนไว้ว่า
---------------------------------------------------------------------
คุณ PUKMTEC C:\AppServ\www\chob\show_test.php on line 55 คืออะไรครับขอดูบรรทัดนี้ด้วย
โค๊ดที่ผมให้ไป ผมโหลดของพี่วินมาแล้วแก้ไข ทดสอบแล้วไม่มีปัญหาอะไรค้นหาได้ กดได้ทุกอัน ผมว่าคุณแก้ผิดตรงไหนหรือเปล่าครับ...
ตอบ...โค๊ดของผมไม่ได้ error บรรทัดที่ 55 นะครับ มีแต่กด next ต่อไปอะไรไม่ได้เลยนะครับ...
เลยผมขออนุญาตส่งโค๊ดมาให้ดูทั้งหมดเลยละกันนะครับ...ส่วน DB ชื่อฟิลด์ก็เหมือนกัน ชื่อ Database : db_customer , Table : tb_customer นะครับ
----------------------------------------------------
AjaxPHPSearchRecordPaging1.php
----------------------------------------------------
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Search,Page) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPSearchRecordPaging2.php';
var pmeters = 'mySearch='+Search;
var pmeters = "mySearch=" + Search + "&myPage=" + Page;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('','1');">
<form name="frmMain">
Search <input type="text" name="txtSearch" id="txtSearch">
<input type="button" name="btnSearch" id="btnSearch" value="Search" OnClick="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1');">
<span id="mySpan"></span>
</form>
</body>
</html>
----------------------------------------------------
AjaxPHPSearchRecordPaging2.php
----------------------------------------------------
<?php
function page_navi($page, $limit, $range, $count){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $page . "');\" ><strong>«</strong></a> ";
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $navi_back . "');\" ><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $i . "');\" ><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $i . "');\" >$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $navi_next . "');\" ><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $total . "');\" ><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'" . $page . "');\" ><strong>$page</strong></a> ";
return $output;
}
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","user","user") or die("Error Connect to Database");
$objDB = mysql_select_db("db_customer");
$page = (isset($_POST['page']))? intval($_POST['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
if(isset($_POST["mySearch"]) and $_POST["mySearch"] != ""){
$condition= " WHERE Name LIKE '%".$_POST["mySearch"]."%'";
}
$sql = "SELECT * FROM tb_customer " .$condition;
// echo $sql . " LIMIT " . $limit_start. "," . $limit_end;
$query_id = mysql_query($sql . " LIMIT " .$limit_start.",". $limit_end);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID</div></th>
<th width="98"> <div align="center">Name</div></th>
<th width="198"> <div align="center">Email</div></th>
<th width="97"> <div align="center">CountryCode</div></th>
<th width="59"> <div align="center">Budget</div></th>
<th width="71"> <div align="center">Used</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($query_id)) {
?>
<tr>
<td><?=$objResult["CustomerID"];?></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><?=$objResult["CountryCode"];?></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<? } ?>
</table>
<br>
<?
echo page_navi($page, $limit_end, 4, $total);
mysql_close($objConnect);
?>
--------------------------------------------------------
ขอขอบคุณล่วงหน้ามา ณ ที่นี้เลยละกัน ผมขอรบกวนฝากเรื่องนี้ด้วยนะครับ ซึ่งผมเองก็สุด ๆ แล้วครับ แก้มาหลายวันแล้ว และโปรแกรมก็จะต้องเสนอต่อหัวหน้าในวันจันทร์นี้แล้ว นะครับ....
---------------------------------------------------
|
 |
 |
 |
 |
Date :
2009-04-02 10:44:11 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูให้หน่อยครับ โค้ดแบ่งหน้าทำไมผมแบ่งไม่ได้เลยครับ
<?php
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 2;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id= '" . $_GET["id"] . "'";
}
$host="localhost";
$user="root";
$pass="123456";
$conn=mysql_connect("localhost","root","123456");
$sql = "SELECT * FROM member" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $connection_id);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $connection_id));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["name"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
ช่วยดูหน่อยนะครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-04-02 15:28:13 |
By :
สร |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเคยเป็นอย่างคุณมาก่อน และพี่ PlaKriM เคยบอกไว้นะครับ
ให้เปลี่ยนตัวแปร ของ $connection_id มาเป็น $conn
55555555555555555555555555555
|
 |
 |
 |
 |
Date :
2009-04-02 17:05:06 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สุดยอดเลย
|
 |
 |
 |
 |
Date :
2009-07-14 08:00:27 |
By :
kai9 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก่งจริงๆ ขอเมลล์ส่วนตัวหน่อยจิ 5555+ โพสมะทันใจ
|
 |
 |
 |
 |
Date :
2009-07-14 08:39:33 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมไม่โพสต์เมล์ครับ อิอิ ติดปัญหาอะไรถามได้ในบอร์ด ถ้าสุดวิสัยจริงๆ โพสต์เมล์ไว้ครับเพ่ ผมจะติดต่อกลับเอง 
|
 |
 |
 |
 |
Date :
2009-07-14 10:49:08 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ว้า ... แย่จัง งั้นเมลล์เค้านะ [email protected]
|
 |
 |
 |
 |
Date :
2009-07-14 12:09:56 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมผมเอาไปทำกระทู้ แล้วมันไม่ยอมให้ id ทีมาทีหลัง ขึ้นหัวข้อแรกคับ
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
?>
<?php
$hostname = "localhost";
$username = "root";
$password = "mysql";
$conn = mysql_connect($hostname, $username, $password) or die ("ไม่สามารถติดต่อ Server ได้");
mysql_query("SET NAMES utf8", $conn);
mysql_query("USE webboard");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 4;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE qid = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM question" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $conn);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $conn));
if($total > 0){
while($rows = mysql_fetch_array($query_id)){
echo $rows["qid"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
มันเป็นอย่างนี้คับ
id
3
5
7
8
Page : 1 2 › [1-4] of 7
|
 |
 |
 |
 |
Date :
2009-08-06 23:02:57 |
By :
hambe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ กำลังติดปัญหาเรื่องแบ่งหน้าพอดี เลย
ขอ bookmark ไว้ก่อนค่อยมาศึกษา
|
 |
 |
 |
 |
Date :
2009-08-08 00:04:54 |
By :
pun05 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ PlaKriM
ช่วยผมหน่อยครับ คือว่า จะแบ่งหน้า แบบ นี้ครับ
<< 1-50 | 51-100 | ... | 200-250 | 251-300 >>
แต่ตอนนี้ผมแบ่ง แบบนี้ได้แล้ว
[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31][32][33][34][35][36][37][38][39][40][41][42][43][44]

ผมอยากจะแบ่งเหมือนข้างบนต้องแก้ตรงไหนบ้างครับ
นี้คือโค๊ด
<?php
mysql_connect('localhost','root','');
mysql_select_db('tbl_pic');
if(!isset($start)){
$start = 0;
}
$limit = '50';
$Qtotal = mysql_query("select * from pic");
$total = mysql_num_rows($Qtotal);
$Query = mysql_query("SELECT * FROM pic ORDER BY num DESC LIMIT $start,$limit");
$totalp = mysql_num_rows($Query);
$check=1;
while($record = mysql_fetch_array($Query)){
$num=$record[num];
$id=$record[id];
$photo1=$record[photo1];
if($check%5==1)
{
echo "<div align='center'>";
echo "<tr>";
}
echo "
<a href='pic/$id/from.php'target='_blank'><img src = /images_baby/$photo1' alt='$id' width='120' height='120' border =0></a>";
if($check%5==0)
{
echo "</tr>";
echo "</div>";
$check=0;
}
$check++;
}
echo "<br>";
?>
ช่วยผมหน่อยครับตอนนี้ มึนไปหมดแล้ว
|
 |
 |
 |
 |
Date :
2009-08-18 14:19:52 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ DownsTream ครับ
คือผมลองทำแล้วครับ ใช้ได้เลยทีเดียว
แต่ผมอยากได้แบบที่ ดึงข้อมูลออกมาแบบนี้ครับ ไม่ทราบว่าทำยังงัยครับช่วยหน่อย
ให้มันโชว์ข้อมูล เป็นแถว แถวละ 5 Colum
ข้อมูล1 ข้อมูล2 ข้อมูล3 ข้อมูล4 ข้อมูล5
ข้อมูล6 ข้อมูล7 ข้อมูล8 ข้อมูล9 ข้อมูล10
อยากให้มันโชว์ข้อมูลแบบนี้ครับ
|
 |
 |
 |
 |
Date :
2009-08-18 16:53:36 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<< 1-50 | 51-100 | ... | 200-250 | 251-300 >>
แบบนี้หรอ 1-50 นั่น หน้าหรือ record
|
 |
 |
 |
 |
Date :
2009-08-18 20:21:32 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้หรือเปล่าไม่รู้ที่ Boou ต้องการ

$scroll_page = 5; //
$per_page = 10; // จำนวนข้อมูลต่อหนึ่งหน้า
$i = 1;
while ($read = mysql_fetch_assoc($sql))
{
echo $read['name'].'    ';
if($i% 5 == 0)
echo '<br />';
$i++;
}
|
 |
 |
 |
 |
Date :
2009-08-19 09:06:25 |
By :
DownsTream |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบข้อความ 55 ครับ
PlaKriM
1-50 คือ ข้อมูลที่1 ถึงข้อมูลที่ 50 อยู่ในหน้า แรก ครับ
|
 |
 |
 |
 |
Date :
2009-08-19 15:02:31 |
By :
Guest |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
$j=1;
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page){
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">" . $i . "-" . $limit . "</font></strong></a> ";
$j += $limit;
}else{
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">" . $j . "-" . (($j+$limit)-1) . "</a> ";
$j += $limit;
}
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= " | <a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
?>
จัดให้แล้วครับ ตามที่ต้องการเปล่า
|
 |
 |
 |
 |
Date :
2009-08-19 22:20:00 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับคุณ PlaKriM
สำหรับการแบ่งหน้า
ท่าน PlaKriM ช่วยผมอีกหน่อย
คือผมทำให้ข้อมูลมีสีพื้นหลังสลับกัน 2 สีได้แล้ว
ตามโค๊ดนี้ครับ
if($bg == "#CCFF66") {
$bg = "#FF66CC";
} else {
$bg = "#CCFF66";
}
echo "<center><table bgcolor='$bg' width='36%' border='0' cellpadding='0' cellspacing='0'> ข้อมูลจากฐานข้อมูล </table>
center>";
แต่ทีนี้ผมจะทำให้สลับ ภาพพื้นหลัง ครับ
ไม่ทราบว่าใช้หลักการเดียวกันได้ไหมครับ
|
 |
 |
 |
 |
Date :
2009-08-20 09:33:29 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลักการเดี่ยวกันครับ แต่เปลี่ยนไปใช้ css ดีกว่า 
|
 |
 |
 |
 |
Date :
2009-08-20 19:49:48 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เสด็จพี่ PlaKriM ท่านเจ๋งจริงๆ จริงใจด้วย หาที่ไหนได้เนี่ย
ขอบคุณมากมาย
|
 |
 |
 |
 |
Date :
2009-08-22 13:22:50 |
By :
peterxp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in D:\AppServ\www\ROY\show_applicant.php on line 24
ERROR Execute [SELECT * FROM applicant ORDER by ID ASC]
ไม่ทราบว่าข้อความนี้หมายความว่าอะไรค่ะ
รบกวนพี่ๆช่วยตอบด้วยนะค่ะ หนูไม่ทราบจริงๆๆค่ะ และพยายามแก้ไขมาหลายวันแล้วไม่สามารถแก้ได้
หนูได้ตั้งค่า DSN แล้วและได้เก็บฐานข้อมูลไว้ใน D:\AppServ\www\ROY\register.mdb
<body>
<?
include("dbconnect.php");
$sql_applicant = "SELECT * FROM applicant ORDER by ID ASC";
$query_applicant = odbc_exec($sql_applicant,$connect_db) or die ("ERROR Execute [".$sql_applicant."]");
$Num_Rows=0;
while (odbc_fetch_row($query_applicant))$Num_Rows++;
$Per_Page = 10; // 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;
?>
<table width="2246" height="113" border="1">
<tr>
<td colspan="14" background="BG/9.jpg"><h5 align="center" class="style5"> APPLICANTS FORM</h5></td>
</tr>
<tr>
<td width="115"><h5 align="center" class="style5">ID</h5></td>
<td width="161"><h5 align="center" class="style5">Titlename </h5></td>
<td width="161"><h5 align="center" class="style5">Firstname </h5></td>
<td width="161"><h5 align="center" class="style5">Lastname</h5></td>
<td width="161"><h5 align="center" class="style5">Birth</h5></td>
<td width="161"><h5 align="center" class="style5">Address</h5></td>
<td width="161"><h5 align="center" class="style5">E-mail</h5></td>
<td width="161"><h5 align="center" class="style5">ID Card</h5></td>
<td width="161"><h5 align="center" class="style5">Telephone</h5></td>
<td width="161"><h5 align="center" class="style5">username </h5></td>
<td width="184"><h5 align="center" class="style5">Course name </h5></td>
<td width="123"><h5 align="center" class="style5">Edit</h5></td>
<td width="178"><h5 align="center" class="style5">Delete</h5></td>
</tr>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$row_applicant = odbc_fetch_array($query_applicant,$i);
?>
<tr>
<td><div align="center"><? print $row_applicant[ID]; ?> </div></td>
<td><div align="center"><? print $row_applicant[titlename]; ?> </div></td>
<td><div align="center"><? print $row_applicant[firstname]; ?> </div></td>
<td><div align="center"><? print $row_applicant[lastname]; ?> </div></td>
<td><div align="center"><? print $row_applicant[birth]; ?> </div></td>
<td><div align="center"><? print $row_applicant[address]; ?> </div></td>
<td><div align="center"><? print $row_applicant[email];?></div></td>
<td><div align="center"><? print $row_applicant[IDcard]; ?> </div></td>
<td><div align="center"><? print $row_applicant[phone]; ?> </div></td>
<td><div align="center"><? print $row_applicant[username]; ?> </div></td>
<td><div align="center"><? print $row_applicant[coursename]; ?></div></td>
<td><div align="center"><a href="edit_applicants.php?ID=<? print $row_applicant[ID];?>"> Edit</a></div></td>
<td><div align="center">
<a href="show_applicant.php?delete=1&ID=<? print $row_applicant[ID]; ?>">Delete</a></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($connect_db);
?>
<h1><a href="student.php" class="style9">Wellcome To Student</a> </h1>
</body>
</html>
ขอบพระคุณพี่PlaKriM มากค่ะ
CODE connect ค่ะ
<?php
$hostname_database = "localhost";
$database_db = "register";
$username_db = "";
$password_db = "";
$connect_db = odbc_connect($database_db , $username_db, $password_db)
or trigger_error(mysql_error(),E_USER_ERROR);
?>
รบกวนด้วยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 00:41:50 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่ายัง connect ไม่ได้นะ DSN ที่ set ไว้ชื่ออะไร
ตามนี้ ทำหรือยัง https://www.thaicreate.com/tutorial/ms-access-dsn-odbc.html
|
 |
 |
 |
 |
Date :
2009-08-23 00:57:43 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DSN ที่ set ไว้ชื่อ register ค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 16:53:56 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DSNก็ทำเหมือนกันทุกอย่างนะค่ะ
ไม่เข้าใจว่าทำไมถึงทำไม่ได้
รบกวนพี่ช่วยหน่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 16:55:29 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$query_applicant = odbc_exec($connect_db, $sql_applicant) or die ("ERROR Execute [".$sql_applicant."]");
ต้องใส่ link resource ก่อน statement
|
 |
 |
 |
 |
Date :
2009-08-23 16:59:54 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่หนูทดสอบการเชื่อมต่อแล้ว
ก็เชื่อมได้นะค่ะ
ไม่เข้าใจว่ามันเกิดจากปัญหาอารายค่ะ
รบกวนพี่ช่วยตอบด้วยนะค่ะ
พยายามค้นหาแล้วและหาหนังสือมาดูก็ไม่ได้คำตอบเลย
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 17:04:44 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
change
odbc_exec($sql_applicant, $connect_db)
to
odbc_exec($connect_db, $sql_applicant)
|
 |
 |
 |
 |
Date :
2009-08-23 17:09:52 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 17:36:10 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วหรอครับ ลองไปเปิดดูฟังก์ชั่นเกี่ยวกับ odbc ใหม่นะครับ
|
 |
 |
 |
 |
Date :
2009-08-23 17:40:22 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ค่ะ ขอรบกวนอีกรอบค่ะ
หนูลองทำตามที่พี่บอกแล้วค่ะ
แต่ก็เป็นแบบเดิมค่ะ
เกิดจากอะไรค่ะ
เกี่ยวข้องกับฐานข้อมูลไหมค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 17:41:39 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้ลอง connect ด้วยโค๊ดนี้ดูก่อนนะครับ
https://www.thaicreate.com/php/php-odbc-ms-access-connect-database.html
ถ้าได้แล้ว ค่อยมาหาบั๊กใหม่
|
 |
 |
 |
 |
Date :
2009-08-23 17:46:09 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำดูแล้วค่ะและปรากฏข้อความนี้ค่ะ
Database Connected
|
 |
 |
 |
 |
Date :
2009-08-23 17:53:01 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาโค๊ดลาสุดมาดู แล้วบอกด้วยว่า error บรรทัดไหน แล้วครอบด้วย PHP Code ด้วยก็ดี
|
 |
 |
 |
 |
Date :
2009-08-23 17:56:12 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
show_student.php
<? include("dbconnect.php"); ?>
<form id="form1" name="form1" method="post" action="show_student.php">
<table width="2246" height="113" border="1">
<tr>
<td colspan="14" background="BG/9.jpg"><h5 align="center" class="style5"> STUDENTS FORM</h5></td>
</tr>
<tr>
<td width="115"><h5 align="center" class="style5">Student ID</h5></td>
<td width="161"><h5 align="center" class="style5">Titlename </h5></td>
<td width="161"><h5 align="center" class="style5">Firstname </h5></td>
<td width="161"><h5 align="center" class="style5">Lastname</h5></td>
<td width="161"><h5 align="center" class="style5">Birth</h5></td>
<td width="161"><h5 align="center" class="style5">Address</h5></td>
<td width="161"><h5 align="center" class="style5">E-mail</h5></td>
<td width="161"><h5 align="center" class="style5">ID Card</h5></td>
<td width="161"><h5 align="center" class="style5">Telephone</h5></td>
<td width="161"><h5 align="center" class="style5">username </h5></td>
<td width="184"><h5 align="center" class="style5">Course name </h5></td>
<td width="123"><h5 align="center" class="style5">Edit</h5></td>
</tr>
<?php
$sql_student = " select * from student ";
$query_student = odbc_exec($connect_db,$sql_student) or die(mysql_error());
$row_student = odbc_fetch_row($query_student );
$Num_Rows = odbc_num_fields($query_student);
while ($row_student = odbc_fetch_row($query_student));
{
?>
<tr>
<td><div align="center"><? print $row_student[studentID]; ?> </div></td>
<td><div align="center"><? print $row_student[titlename]; ?> </div></td>
<td><div align="center"><? print $row_student[firstname]; ?> </div></td>
<td><div align="center"><? print $row_student[lastname]; ?> </div></td>
<td><div align="center"><? print $row_student[birth]; ?> </div></td>
<td><div align="center"><? print $row_student[address]; ?> </div></td>
<td><div align="center"><? print $row_student[email];?></div></td>
<td><div align="center"><? print $row_student[IDcard]; ?> </div></td>
<td><div align="center"><? print $row_student[phone]; ?> </div></td>
<td><div align="center"><? print $row_student[username]; ?> </div></td>
<td><div align="center"><? print $row_student[coursename]; ?></div></td>
<td><div align="center"><a href="edit_student.php?edit_ID=<? print $row_student[studentID];?>"> Edit</a></div></td>
</tr>
<?
}
?>
</table>
</form>
<?
$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 TeacherID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<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> ";
}
?>
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in C:\AppServ\www\ROY\show_student.php on line 44
|
 |
 |
 |
 |
Date :
2009-08-23 18:43:40 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$objConnect = odbc_connect("register","","") or die("Error Connect to Database");
$strSQL = "select * from student";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
while($objResult = odbc_fetch_array($objExec))
{
echo $objResult[firstname]."<br>";
}
ลองรันแค่นี้ดูนะครับ ว่าเป็นบ้าง
|
 |
 |
 |
 |
Date :
2009-08-23 20:51:03 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รันได้ค่ะ
ขอบคุณพี่มากนะค่ะ
ขอรบกวนถามหน่อยนะค่ะว่าไม่ทราบเป็นเพราะสาเหตุอะไรค่ะ จะได้เก็บไว้เป็นความรู้ หากเจอปัญหาคราวหน้าจะได้ทราบค่ะว่าเกิดสาเหตุนี้ และควรแก้แบบนี้
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 22:45:24 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงๆ ไม่ใช่อะไรหรอก ผมอ่านโค๊ดน้องแล้ว ผมหาบั๊กไม่เจอ เลยเอาโค๊ดในบทเรียนมาแก้ให้ลองรันดู 
|
 |
 |
 |
 |
Date :
2009-08-23 22:48:43 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่มากนะค่ะที่ให้คำปรึกษา และให้คำแนะนำเป็นอย่างดีมาตลอด ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-08-23 23:01:29 |
By :
bear48 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
https://www.thaicreate.com/php/forum/008240.html
รบกวนด้วยนะครับ
|
 |
 |
 |
 |
Date :
2009-08-24 10:55:03 |
By :
po |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากข้อความที่ NO.60 ครับ
คุณ PlaKriM ครับผมขอ Code หน่อยครับ คือผมจะเอามา สลับรูปพื้นหลังที่คุณบอกว่า ใช้ css อ่ะครับ
ขอหน่อยนะครับ จะของพระคุณเป็นอย่างสูง
|
 |
 |
 |
 |
Date :
2009-08-24 15:38:27 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<style>
.row1{
background:#F6C url(images/odd.gif);
}
.row2{
background:#CF6 url(images/odd.gif);
}
</style>
if($style == "row1") {
$style = "row1";
} else {
$style = "row2";
}
echo "<center><table class=" . $style . " width='36%' border='0' cellpadding='0' cellspacing='0'> ข้อมูลจากฐานข้อมูล </table>
center>";
จัดให้อีก กำลังเครียดกับโค๊ดชาวบ้าน 
|
 |
 |
 |
 |
Date :
2009-08-24 15:52:24 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สมมุติ มี web hosting support php ผมก็ upload ไฟล์ access ขึ้นไปบนเว็บ ทำอย่างไร จะให้ php ดึง ข้อมูลจาก access ออกมาแสดงผลได้
อยู่ที่ไหนก็เปิด ได้ ใครบ้าง code บ้างขอบคุณคร้าบบบบบบบ
|
 |
 |
 |
 |
Date :
2009-08-25 13:44:22 |
By :
po |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณเป็นอย่างสูง PlaKriM NO.82
ถามตอบอีกหน่อยครับ ถ้าหากจะสลับประมาณ 6 ภาพ เราต้องเพิ่ม ตรงไหนบ้างครับ
ผมลองเพิ่ม
<style>
.row1{
background:#F6C url(images/g001.jpg);
}
.row2{
background:#CF6 url(images/g002.jpg);
}
.row3{
background:#CF6 url(images/g003.jpg);
}
</style>
<?
if($style == "row3") {
$style = "row1";
} else {
$style = "row2";
} else {
$style = "row3";
}
echo "<center>
<table class='.$style.' width='300' height= '125' border='0' cellpadding='0' cellspacing='0'> <td><div align='center'>$message</div></td>
</table>
</center>";
}
?>
แบบนี้ครับมัน error ครับ ไม่ทราบว่าเพิ่มแบบไหนกันครับ
และผมสงสัยตรง #CF6 มันคืออะไรเหรอครับ
|
 |
 |
 |
 |
Date :
2009-08-25 17:36:39 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
#CF6 = #CCFF66
ถ้าจะสลับถึงหกแบบนั้นผมแนะนำให้ใช้
<style>
.row1{
background:#F6C url(images/g001.jpg);
}
.row2{
background:#CF6 url(images/g002.jpg);
}
.row3{
background:#CF6 url(images/g003.jpg);
}
.row4{
background:#CF6 url(images/g004.jpg);
}
.row5{
background:#CF6 url(images/g005.jpg);
}
.row6{
background:#CF6 url(images/g006.jpg);
}
</style>
Code (PHP)
<?php
$i=1;
while($row=mysql_fetch_assoc($query)){
if($i%6=0) $i=1; // ตรงนี้เช็คดูหน่อยผมอาจผิด
echo "<center>
<table class='row".$i." width='300' height= '125' border='0' cellpadding='0' cellspacing='0'> <td><div align='center'>$message</div></td>
</table>
</center>";
}
?>
|
 |
 |
 |
 |
Date :
2009-08-25 20:08:16 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
No. 83 hosting จะมี software สำหรับจัดการมาให้ เช่น cpanel , direct admin เป็นต้น จากนั้นอัปโหลด db ไปไว้ยัง path ที่ต้องการ แล้วไป set odbc ผ่าน software ที่ hosting มีให้ แล้ว connect ด้วย odbc
หรือจะ connect ด้วย ado ก็หาดูในบทเรียน ส่วนต้องเปลี่ยน attribute ให้เป็น เท่าไหรนั้นตั้งกระทู้ถามดีกวา ผมไม่เคยใช้ access
|
 |
 |
 |
 |
Date :
2009-08-25 20:17:30 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
No. 85
ครับผิดตรงนั้นจริงๆ ครับ แล้วผมก็แก้ไม่ได้ด้วย 
ขอร้องช่วยแก้ให้ทีนะครับ คุณ พี่ PlaKriM
|
 |
 |
 |
 |
Date :
2009-08-26 14:24:14 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณพี่ PlaKriM ไม่ช่วยแล้ว ~.~"
|
 |
 |
 |
 |
Date :
2009-08-31 13:04:54 |
By :
okboou |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ PlaKriMสำหรับของที่นำมาปล่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-08-31 13:11:51 |
By :
saowaluk052 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ๆๆๆครับทำไมผมทำแล้วในแต่ละหน้ามันมีข้อมูลเหมือนหน้าแรกเปะเลยครับ
ต้องแก้ยังไงอะครับ
Code (PHP)
<?php
date_default_timezone_set('Asia/Bangkok');
?>
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output; }
?>
<HTML>
<HEAD><TITLE>รายงานผู้เข้าร่วมโครงการอบรมระบบ ISO</TITLE>
<link href="css.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD>
<body>
<table width="1097" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1121"><div align="center"><img src="photo/logosocail.jpg" width="130" height="112" onload="MM_openBrWindow('Description.php','ค&','width=350,height=100')"></div></td>
</tr>
</table>
<table width="1096" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center" class="headre">ISO<br>
</div></td>
</tr>
<tr>
<td><div align="right" class="infoheader">วันที่รายงาน <?php echo date("Y-m-d"); ?></div></td>
</tr>
</table>
<table width="1095" border="1" cellpadding="1" cellspacing="1">
<tr bgcolor="#0066FF">
<td width="64" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ลำดับที่</div></td>
<td width="116" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ชื่อ</div></td>
<td width="131" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">สกุล</div></td>
<td width="77" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ชื่อเล่น</div></td>
<td width="124" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">เบอร์โทรศัพท์เคลื่อนที่</div></td>
<td width="111" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">เบอร์โทรศัพท์บ้าน</div></td>
<td width="107" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">อีเมลล์</div></td>
<td width="234" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ที่อยู่</div></td>
<td width="83" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">รูปภาพ</div></td>
</tr>
<?php
$count=0;
include "connect.php";
$sql="select * from iso order by id desc";
$resu=mysql_db_query($dbname,$sql);
while($record=mysql_fetch_array($resu)){
$count++; ?>
<tr class="infoheader">
<td class="infoheader" align="center"><?php echo $count ?></td>
<td class="infoheader"><?php echo $record[name] ?></td>
<td class="infoheader"><?php echo $record[lastname] ?></td>
<td class="infoheader"><?php echo $record[nickname] ?></td>
<td class="infoheader"><?php echo $record[mobile] ?></td>
<td class="infoheader"><?php echo $record[home] ?></td>
<td class="infoheader"><?php echo $record[email] ?></td>
<td class="infoheader"><?php echo $record[address] ?></td>
<td align="center" class="infoheader"><?php
$id=$record[id];
include "connect.php";
$sql1="SELECT * FROM iso where id='$id'";
$result1 = mysql_db_query($dbname,$sql1);
while($r1 = mysql_fetch_array($result1)){
$photo=$r1[photo];
?>
<?
if ($photo=="")
{echo "ยังไม่มีรูปครับ";}
else
{
echo "<CENTER><IMG SRC='photo/$photo' width='50 pixels' heigth='50 pixels'></CENTER><BR>";
}
}//while
?>
</td>
</tr>
<? }
mysql_close();
?>
</table>
<?php
include "connect.php";
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 1;
$limit_start = ($page-1)*$limit_end;
$send = "id";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id = 'id'" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM iso". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $c);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $c));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
}
echo "\n<div style=\"float:left;\">total : " . $total ." record | " . $page ."/" . $total ." " . page_navi($page, $limit_end, 3, $total, $send) . "</div>";
}
?>
</BODY>
</HTML>
|
 |
 |
 |
 |
Date :
2009-10-16 18:48:29 |
By :
leehoon5 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
date_default_timezone_set('Asia/Bangkok');
?>
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output; }
?>
<HTML>
<HEAD><TITLE> ISO</TITLE>
<link href="css.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD>
<body>
<table width="1097" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1121"><div align="center"><img src="photo/logosocail.jpg" width="130" height="112" onload="MM_openBrWindow('Description.php','คำอธิบายการพิมพ์รายงาน','width=350,height=100')"></div></td>
</tr>
</table>
<table width="1096" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center" class="headre"> ISO<br>
</div></td>
</tr>
<tr>
<td><div align="right" class="infoheader"><?php echo date("Y-m-d"); ?></div></td>
</tr>
</table>
<table width="1095" border="1" cellpadding="1" cellspacing="1">
<tr bgcolor="#0066FF">
<td width="64" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ลำดับที่</div></td>
<td width="116" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ชื่อ</div></td>
<td width="131" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">สกุล</div></td>
<td width="77" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ชื่อเล่น</div></td>
<td width="124" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">เบอร์โทรศัพท์เคลื่อนที่</div></td>
<td width="111" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">เบอร์โทรศัพท์บ้าน</div></td>
<td width="107" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">อีเมลล์</div></td>
<td width="234" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">ที่อยู่</div></td>
<td width="83" bgcolor="#FFFFFF" class="infomedium"><div align="center" class="infoheader33">รูปภาพ</div></td>
</tr>
<?php
$count=0;
include "connect.php";
$page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
$limit_end = 20;
$limit_start = ($page-1)*$limit_end;
$sql="select * from iso order by id desc";
$resu=mysql_db_query($dbname,$sql . " limit " . $start. "," . $limit);
$total = mysql_num_rows(mysql_db_query($dbname,$sql));
while($record=mysql_fetch_array($resu)){
$count++; ?>
<tr class="infoheader">
<td class="infoheader" align="center"><?php echo $count ?></td>
<td class="infoheader"><?php echo $record[name] ?></td>
<td class="infoheader"><?php echo $record[lastname] ?></td>
<td class="infoheader"><?php echo $record[nickname] ?></td>
<td class="infoheader"><?php echo $record[mobile] ?></td>
<td class="infoheader"><?php echo $record[home] ?></td>
<td class="infoheader"><?php echo $record[email] ?></td>
<td class="infoheader"><?php echo $record[address] ?></td>
<td align="center" class="infoheader"><?php
$id=$record[id];
include "connect.php";
$sql1="SELECT * FROM iso where id='$id'";
$result1 = mysql_db_query($dbname,$sql1);
while($r1 = mysql_fetch_array($result1)){
$photo=$r1[photo];
?>
<?
if ($photo=="")
{echo "ยังไม่มีรูปครับ";}
else
{
echo "<CENTER><IMG SRC='photo/$photo' width='50 pixels' heigth='50 pixels'></CENTER><BR>";
}
}//while
?>
</td>
</tr>
<? }
mysql_close();
?>
</table>
<?php
echo "\n<div style=\"float:left;\">total : " . $total ." record | " . $page ."/" . $total ." " . page_navi($page, $limit_end, 3, $total) . "</div>";
?>
</BODY>
</HTML>
|
 |
 |
 |
 |
Date :
2009-10-16 22:23:55 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ PlaKriM
เป็นคนบุรีรัมย์ เหรอครับ ^-^
ถ้าใช่ ก็.... โค้นนน บ้านเดียวกัน 5555
|
 |
 |
 |
 |
Date :
2009-10-18 10:45:21 |
By :
yomaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปล่าครับ พี่วินต่างหากคนบุรีรัมย์ ผมคนศรีสะเกษติดกับเขมรครับ บ้านเดีียวกันกับตาเดี่ยว อิอิ 
|
 |
 |
 |
 |
Date :
2009-10-18 18:57:07 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่จริ๊งงง บ่เสื่ออออออออออออออออ
ข้อยคนกุงเทพพพพพพพพพพพพพพพพ
ฟังสำเนียงกะฮู่ววววววววววววว
|
 |
 |
 |
 |
Date :
2009-11-27 14:20:05 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
              :
ช่างกล้าาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาาา
|
 |
 |
 |
 |
Date :
2009-11-27 14:32:02 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่ายยยย .... ครัยก็ไม่รุ อิอิ
|
 |
 |
 |
 |
Date :
2009-11-27 20:31:11 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เง้อ...เค้ามะรู้เรื่อง แง่บ แงบ 
|
 |
 |
 |
 |
Date :
2009-11-27 21:26:17 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขูดมาแซวกันทามมายยยยยยยยยยยย 
|
 |
 |
 |
 |
Date :
2009-11-28 03:08:42 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังเล่นกันได้ .... ฟังไม่รู้เรี่ยงงงง อะไรก็ไม่รู้บุ๊ 
|
 |
 |
 |
 |
Date :
2009-11-28 03:41:34 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
wow กระทู้ครบ100โพสแล้วนั้นผมขอเป็นโพสที่101นะ เทห์ปะคับ ยังไงๆ โค๊ดแบ่งหน้า PHP+MySQL ยังคงอยู่กับเราตลอดไปนะคับ อ้าวสู้กันต่อไปอยากทราบว่าใครจะเป็นผู้ชายตอง1ของกระทู้นี้นะคับ
|
 |
 |
 |
 |
Date :
2009-11-28 11:14:26 |
By :
gofgof |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2009-11-28 17:44:10 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ชอบกระทู้นี้จัง....ขอบคุณพี่ plakrim มั่กมากนะค่ะ
|
 |
 |
 |
 |
Date :
2009-12-15 22:42:11 |
By :
fumio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาใช้ใช้งานยังไง คะ คือหนูเพิ่งหัดทำ แล้วต้องส่งงานพรุ่งนี้แล้ว
เอาโดที่พี่โพส ไปก็อบละใช้ได้เลยหรอวะ
ก็อบวางตรงหน้าที่เราต้องการแบ่งใช่ไหมคะ
|
 |
 |
 |
 |
Date :
2009-12-16 02:11:49 |
By :
Figaro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือว่ามัน ไม่แสดงเพจละ 5 หน้า ตามที่เรา กำหนดนะคะ พอดีไปเอาโค้ดพี่สักคนในห้องนี้ละคะมา แต่ว่ามันไม่แสดงคะ
และพอไปเพจ2มันก้อแสดงข้อมูลทั้งหมด เพจ3ก้อแสดงทั้งหมด อย่างงี้อ่าคะ คิดว่าน่าจะผิดตรงการ คิวรี่นะคะ
แต่แก้แระยังไม่ได้อ่าคะ ทำไงดี ช่วยดูให้หน่อยนะคะ
Code (PHP)
//----------------คำสั่ง SQL ให้เลือกใช้งานตาราง ------------------------------//
$sql = "SELECT * FROM data order by P_id desc";
//--------------กำหนดจำนวนข้อมูลแสดงผลต่อ 1 หน้า ---------------------------//
$per_page = 5;
//$page_start =0;
//-----------------------------------------------------------------------//
if ( !$page )
$page = 1;
$prev_page = $page - 1;
$next_page = $page + 1;
$result = mysql_query( $sql );
$page_start = ( $per_page * $page) - $per_page;
$num_rows = mysql_num_rows( $result );
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;
if ( ( $page > $num_pages ) || ( $page < 0 ) )
print "จำนวน $page มากกว่า $num_pages";
//-------------------คำสั่ง SQL กำหนดลิมิต ให้แสดงผลต่อ 1 หน้า---------------------------//
$sql .= " LIMIT $page_start, $per_page";
$result = mysql_query( $sql );
$dbquery = mysql_db_query($dbname,$sql);
$cols = 5; //กำหนดจำนวนคอลั่ม
$c = $cols;
?>
<table width="100%" border="0"><tr>
<?
while($result = mysql_fetch_array( $dbquery)) {
$c --;
?>
<?
if($c == 0) {
$c = $cols;
?></tr> <? } } ?> </table>
<br /><br /><!- - แสดงผลจำนวนเรคคอร์ดของข้อมูล จำนวนหน้าและลิงค์หน้าต่อๆไป - - !>
รวม <b><?php echo $num_rows; ?></b> แสดงอยู่ <b><?php echo $num_pages; ?></b> หน้า <br />
<?php //------------------- สร้างปุ่มย้อนกลับ -------------------------//
if ( $prev_page )
echo "<a href=\"$PHP_SELF?page=$prev_page\"><<กลับไป </a>";
//--------------------- สร้างตัวเลขหน้า -----------------------------//
for ( $i=1; $i<=$num_pages; $i++ )
{
if ( $i != $page)
echo "[<a href=\"$PHP_SELF?page=$i\">$i</a>]";
else
echo " <b>$i</b> ";
}
//-------------------- สร้างปุ่มเดินหน้า --------------------------------//
if ( $page != $num_pages )
echo "<a href=\"$PHP_SELF?page=$next_page\"> หน้าต่อไป >></a>";
?>
|
 |
 |
 |
 |
Date :
2009-12-16 11:16:49 |
By :
kakaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาทุกกระทู้ แปวว
|
 |
 |
 |
 |
Date :
2009-12-16 17:13:10 |
By :
Gumme |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากกกกค่ะ (^ ^)(_ _)(^ ^)
รบกวนต่อนะคร้าาา...
เอ่อ....แบ่งหน้าได้แล้ว และถ้าต้องการให้สามารถเลือกได้ว่าต้องการจะแบ่ง หน้าละเท่าไหร่ คือ แสดงข้อมูลออกมาโดยแบ่งหน้าให้แล้ว หน้าละ 10 และผู้ใช้ก็ยังสามารถเลือกจาก drop down ได้ด้วยว่าจะให้มันแบ่งหน้า หน้าละเท่าไหร่ เช่น หน้าละ 5, 10, 20
จะต้องเขียนยังไงค่ะ.... ขอตัวอย่างโค้ดด้วยนะคะ
|
 |
 |
 |
 |
Date :
2009-12-19 22:57:51 |
By :
fumio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = (isset($_REQUEST['record']))? intval($_REQUEST['record']) : 5;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_REQUEST["record"]) and $_REQUEST["record"] != ""){
$send = "record =" . $_REQUEST["record"];
}
$sql = "SELECT * FROM product" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $connection_id);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $connection_id));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["product_name"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
<select name="record">
<option value="5" <?if($limit_end = 5) echo " selected = \"selected\"";?>>5</option>
<option value="10" <?if($limit_end = 10) echo " selected = \"selected\"";?>>10</option>
<option value="15" <?if($limit_end = 15) echo " selected = \"selected\"";?>>15</option>
</select>
ประมาณนี้น่าจะได้
|
 |
 |
 |
 |
Date :
2009-12-19 23:12:20 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้วว รวดเร็วจังค่ะ
+1 ^^
แต่ตอนนี้ง่วงแล้วว ~.~
พรุ่งนี้เริ่มปฏิบัติการ!!!! (พรุ่งนี้! ก้อวันนี้แล้วสิ - -" )
ขอบคุณมากมายค่าาา(^ ^)(_ _)(^ ^)
|
 |
 |
 |
 |
Date :
2009-12-20 01:40:07 |
By :
fumio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กระทู่นี้ยาวเลยน่ะ
พี่ PlaKriM
|
 |
 |
 |
 |
Date :
2009-12-20 02:27:44 |
By :
parita |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เย้!!! ได้แล้วๆๆ คร้าาา
ขอบคุณพี่ plakrim มากๆๆๆ เลยนะคะ (^ ^)(_ _)(^ ^)(_ _)(^ ^)

zetsumyou!!!
|
 |
 |
 |
 |
Date :
2009-12-20 02:45:20 |
By :
fumio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ PlaKriM นะคะ
|
 |
 |
 |
 |
Date :
2009-12-26 02:12:29 |
By :
Bowwy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
555+
ผมเกิดมาเพื่อสิ่งนี้ อิอิ
|
 |
 |
 |
 |
Date :
2009-12-26 09:43:33 |
By :
danya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอถามหน่อยครับ
เราจะรู้จำนวณ หน้าทั้งหมดยังไงครับ
|
 |
 |
 |
 |
Date :
2010-01-27 20:38:57 |
By :
vicious |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าเกิดว่าเราอยากจะใส่ ORDER BY id DESC เอาไว้ตรง ไหนดีครับ
|
 |
 |
 |
 |
Date :
2010-02-02 06:23:04 |
By :
babybaboza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ละครับ
เอาไว้ตรงบรรทัดที่ 13 
Code (PHP)
$query_id = mysql_query($sql . " ORDER BY ne_id DESC LIMIT " . $limit_start. "," . $limit_end);
|
 |
 |
 |
 |
Date :
2010-02-02 06:33:07 |
By :
babybaboza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วเราจะใส่เงื่อนไขตรงไหนคับ อย่างเช่น where name = 'peter' อะไรทำนองนี้คับ รบกวนหน่อยนะคับ
|
 |
 |
 |
 |
Date :
2010-03-13 01:45:47 |
By :
rokie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามไม่เคลีย คือแบบ โค้ดที่คุณ plakrim ให้มาตอนแรกอ่ะคับ อันแรกเลย เราจะใส่เงื่อนไขตรงไหนคับ ถ้าถามอะไรไม่ค่อยฉลาดขอโทษด้วยนะคับ เช่น where name = 'peter'
|
 |
 |
 |
 |
Date :
2010-03-13 01:56:51 |
By :
rokie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแก้อย่างที่บอกแล้วนะคับ ปรากฏว่ามันก็แสดงออกมาเหมือนไม่ใส่เงื่อนไขเหมือน select * ธรรมดาหน่ะคับ รบกวนอีกทีนะคับ ถ้าผมผิดผลาดตรงไหนข้ออภัยด้วยคับ
Code (PHP)
$host="localhost";
$username="";
$pass_word="";
$db="db_edm_mn";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้") ;
$page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
$limit_end = 20;
$limit_start = ($page-1)*$limit_end;
$sql = "select * from tb_massage limit " . $limit_start. "," . $limit_end;
page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
?>
<?
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 10;
$limit_start = ($page-1)*$limit_end;
///////ในส่วนตรงนี้ผมลองทำตามที่บอกประกอบความเข้าใจของผม ผมเข้าใจคลาดเคลื่อนจากที่บอกยังไงรบกวนชี้แนะด้วยคับ
$send = "";
if(isset($_GET["1234"]) and $_GET["1234"] != ""){
$send = "password_msg =" . $_GET["1234"];
$condition= " WHERE password_msg = '" . $_GET["1234"] . "'";
}
/////////////////////////////////////////////////////////////////////////////////////////////
$sql = "SELECT * FROM tb_massage " . $condition ;
$query_id = mysql_query($sql . " order by id_msg desc LIMIT " . $limit_start. "," . $limit_end);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["password_msg"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-03-13 11:19:29 |
By :
rokie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $send= ส่งตัวแปรอะไรไปด้วย
# $current_style = css สำหรับหน้าปัจจุบัน
# $other_style = css สำหรับอื่นๆ รวมถึง Prev Next First Last
# $target= อันนี้รู้ๆ กัน
#######################################################################
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 10;
$limit_start = ($page-1)*$limit_end;
///////ในส่วนตรงนี้ผมลองทำตามที่บอกประกอบความเข้าใจของผม ผมเข้าใจคลาดเคลื่อนจากที่บอกยังไงรบกวนชี้แนะด้วยคับ
$send = "";
if(isset($_GET["1234"]) and $_GET["1234"] != ""){ // แน่ใจหรอว่าตัวแปรที่ส่งมาชื่อ 1234
$send = "password_msg =" . $_GET["1234"]; // แล้วทำไมจะให้ส่งไปในชื่อ password_msg
$condition= " WHERE password_msg = '" . $_GET["1234"] . "'";
}
# เดาเอาละกันว่าตัวแปรชื่อ password_msg เอา ตัวนี้ไปแทนข้างบนละกัน
# if(isset($_GET["password_msg"]) and $_GET["password_msg"] != ""){
# $send = "password_msg =" . $_GET["password_msg"];
# $condition= " WHERE password_msg = '" . $_GET["password_msg"] . "'";
#}
/////////////////////////////////////////////////////////////////////////////////////////////
$sql = "SELECT * FROM tb_massage " . $condition ;
$query_id = mysql_query($sql . " order by id_msg desc LIMIT " . $limit_start. "," . $limit_end);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
while($rows = mysql_fetch_assoc($query_id)){
echo $rows["password_msg"]."<br>";
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . "-" . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
|
 |
 |
 |
 |
Date :
2010-03-15 03:35:15 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เฮ้อ.........อยากเกินขนาด......แต่ ต้องการมากเรยค่ะ พยามแปลงยังๆงก้อแปลงมะด้สากทีค่ะ
มันเออสะเร่อตลอดเรยค่ะ ช่วยดูให้หน่อยค่ะว่าต้องแก้ตรงไหนบ้างค่ะ รบกวนหน่อยนะค่ะอยากได้จิงๆๆ โค้ดนี้ใช้งานได้ปกตินะค่ะแปลงมาจากwebนี้เหมือนกันค่ะ แต่จะเอาที่แปลงใช้งานได้แร้วมาแปลงเปนแบบของพี่ อีกทีมันไม่ได้อ่าค่ะ
Database ORACLE นะค่ะ
ขอบพระคุณเปนอย่างสูงสุด
Code (PHP)
<?
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="ajax_framework.js"></script>
<script>
//======================================= ซ่อนตารางคำถาม ======================================================
function showQuestionForm() {
document.getElementById('tb_tech').style.display = 'none';
document.getElementById('post_board').style.display = 'block';
document.getElementById('bt_post').style.display = 'none';
}
//======================================= ตรวจสอบฟอร์มคำถาม ===================================================
function checkFormQuestion() {
if(post_board.elements['post_topic'].value=="" ||
post_board.elements['post_detail'].value=="" ) {
document.getElementById('show_post').innerHTML = 'ใส่ข้อมูลไม่ครบ';
return;
}
postTopic();
document.getElementById('show_post').innerHTML = 'กำลังส่งข้อมูล';
document.getElementById('post_board').reset();
}
//======================================= ส่งข้อมูลไปเก็ยในdatabase ==============================================
function postTopic() {
var data = getFormData('post_board');
var URL = "admin_webboard_question_ss.php";
ajaxLoad('post',URL,data,'show_post');
}
//================================== ฟังชั่นในการเรียกโชว์คำถามในwebboard ===========================================
function showQuestion() {
document.getElementById('post_board').style.display = 'none';
document.getElementById('show_post').innerHTML = '';
ajaxLoad('post',"admin_webboard_show_question.php",'','show_question');
document.getElementById('bt_post').style.display = 'block';
}
//================================= ฟั่งชั่น reset form post ======================================================
function resetFormPost() {
document.getElementById('post_board').reset();
}
//================================ ฟั่งชั่น ส่งค่าidหัวข้อกระทู้ =======================================================
function checkQuestion(qid) {
var data = 'data=' + qid;
ajaxLoad('post','check_question.php',data,"");
}
//============== ลบคำถาม =======================================================================================
function deleteQuestion(qid) {
if(!confirm('Delete this question?')) {
return;
}
var data = "qid=" + qid;
var URL = "admin_delete_question.php";
ajaxLoad('post', URL, data, '');
}
//=============================================== อัพเดตtableคำถาม ===============================================
function showUpdateTable() {
document.getElementById('tb_tech').style.display = 'none';
ajaxLoad('post',"admin_webboard_show_question.php",'','show_question');
}
</script>
</head>
<body>
<?php
$topic1 = $_SESSION['topic'];
include("connectOracle.php");
$strSQLcount = "SELECT QID,Q_TOPIC,Q_DATE,USERNAME FROM QUESTION ";
$strSQLcount .="WHERE TOPIC_ID = ".$topic1." ORDER BY QID DESC ";
$objParseCount = oci_parse ($objConnect, $strSQLcount);
oci_execute ($objParseCount,OCI_DEFAULT);
$s1 = oci_parse($objConnect, "alter session set nls_date_format='DD-MM-YYYY'");
oci_execute($s1);
$Num_Rows=oci_fetch_all($objParseCount, $Result);
$Per_Page = 4; // Per Page
$maxlink = 2; // จำนวนหน้าที่ต้องการให้แสดง
$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;
}
$strSQL = "select * from
( SELECT rownum mynum,QID,Q_TOPIC,Q_DATE,USERNAME FROM QUESTION WHERE TOPIC_ID = ".$topic1." ORDER BY QID)
where mynum between $Page_Start and $Page_End";
$objParse = oci_parse ($objConnect, $strSQL);
oci_execute ($objParse,OCI_DEFAULT);
?>
<div id="bt_post"><div align="left"><a href="javascript:void(O)" onclick="showQuestionForm()">[ ตั้งหัวข้อเรื่อง ]
</a> </div>
<span id="alert_login" style="color:#FF0000" ></span></div>
<div id="show_question" > </div>
<table id="tb_tech" width="787" height="52" border="1" background="images/bgr_html1.gif"
style="border-collapse:collapse;" bordercolor="#FF0000" >
<tr>
<td width="46"><div align="center">ลำดับ</div></td>
<td width="281"><div align="center">หัวเรื่อง</div></td>
<td width="80"><div align="center">วันที่โพสต์</div></td>
<td width="22"><div align="center">ดู</div></td>
<td width="30"><div align="center">ตอบ</div></td>
<td width="82"><div align="center">ผู้โพสต์</div></td>
<td width="134"><div align="center">วันที่ตอบล่าสุด</div></td>
<td width="60"><div align="center">ลบ</div></td>
</tr>
<?php
$r=0;
while($row = oci_fetch_array($objParse,OCI_BOTH)){
$taid = $row['QID'];
$r++;
$objQue1 = "SELECT * FROM ANSWER ";
$objQue1 .="WHERE QID = ".$taid." ORDER BY AID DESC ";
$ques1 = oci_parse($objConnect,$objQue1);
$s = oci_parse($objConnect, "alter session set nls_date_format='DD-MM-YYYY'");
oci_execute($s);
oci_execute($ques1);
$i1 = 0;
while(oci_fetch_array($ques1,OCI_BOTH)) {
$i1++;
}
?>
<tr>
<td width="46"><? echo "$r "; ?></td>
<td><div align="left"><a href="javascript:loaddoc()" onclick="checkQuestion(<? echo $row['QID']; ?>)">
<? echo $row['Q_TOPIC']; ?></a></div></td>
<td><? echo ($row['Q_DATE']); ?></td>
<td> </td>
<td><? echo $i1 ?></td>
<td><? echo $row['USERNAME']; ?></td>
<td> </td>
<td><button onclick="deleteQuestion(<? echo $row['QID']; ?>)">Delete</button></td>
</tr>
<? } ?>
</table>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href=javascript:loaddoc('$_SERVER[SCRIPT_NAME]?Page=$Prev_Page')><< Back</a> ";
}
for($i=1; $i<=$Num_Pages && $maxlink > 0; $i++){
if($i != $Page)
{
echo "[ <a href=javascript:loaddoc('$_SERVER[SCRIPT_NAME]?Page=$i')>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href =javascript:loaddoc('$_SERVER[SCRIPT_NAME]?Page=$Next_Page')>Next>></a> ";
}
oci_close($objConnect);
?>
<form id="post_board" style="display:none">
<p>TOPIC:</p>
<p>
<input type="text" id="post_topic" />
</p>
<p>DETAIL:</p>
<p>
<textarea id="post_detail" cols="45" rows="5"></textarea>
</p>
<p><button onclick="checkFormQuestion()">Post</button> <button onclick="resetFormPost()">Reset</button> </p>
</form>
<div id="show_post"> </div>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-03-15 07:18:27 |
By :
Mint |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูโค๊ตหั้ยทีคับ
มันแบ่งหน้าได้คับ แต่เวลาคลิ๊กลิ้งหน้าอื่นมันไม่แสดงข้อมูลคับ
Code (PHP)
<?
$id_subject =$_SESSION['id_subject'];
$id_type=$_POST[id_type];
$day=$_POST[day];
$month=$_POST[month];
$year=$_POST[year];
$day2=$_POST[day2];
$month2=$_POST[month2];
$year2=$_POST[year2];
include "startconnect.inc";
$strSQL = "SELECT * FROM data where date >= '$year-$month-$day' and date <= '$year2-$month2-$day2'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 20; // 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 date desc LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
</span>
<span class="style3">
<?
echo "<P><B>ข้อมูล</B></P>
<table border='1'>
<tr BGCOLOR='#E8E8E8'>
<td><center><b>เลขที่</b></center></td>
<td><center><b>วันที่</b></center></td>
<td><center><b>บัญชี</b></center></td>
<td><center><b>จำนวนเงิน</b></center></td>
<td><center><b>[แก้ไข]</b></center></td>
<td><center><b>[ลบ]</b></center></td>
<td><center><b>[ดูข้อมูล]</b></center></td>
</tr>";
while($row=mysql_fetch_array($objQuery)){
$iddata=$row[iddata];
$date=$row[date];
$money=$row[money];
$idaccount=$row[idaccount];
$sql2="select account from account where idaccount='$idaccount'";
$table2=mysql_query($sql2,$Conn) or die ("ไม่สามารถเรียกดูข้อมูลในเทเบิลได้");
$row2=mysql_fetch_array($table2);
$account=$row2[account];
echo "
<tr>
<td>$iddata</td>
<td>$date</td>
<td>$account</td>
<td>$money</td>
<td><a href=\"edit_budget.php?id_edit=$iddata\">[แก้ไข]</a></td>
<td><a href=\"delete_budget.php?id_del=$iddata\"onclick=\"return confirm('ยืนยันการลบเลขที่ใบสำคัญ $iddata ออกจากระบบ')\">[ลบ]</a></td>
<td><a href=\"view_budget.php?id_view=$iddata\">[ดูข้อมูล]</a></td>
</tr>";
}
echo "</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> ";
}
?>
|
 |
 |
 |
 |
Date :
2010-03-16 10:35:37 |
By :
arasked |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ Mint ตั้งกระทู้ใหม่ดีกว่าไหมครับ โค๊ดพี่วิน เดี๋ยวพี่วินมาช่วยดูให้ Oracle ผมยังไม่ได้เขียนไว้อะ ว่างๆ จะเขียน class มาแปะบ้างเหมือนกัน แต่เมื่อไหร่จะว่างนั้น ก็ยังไม่รู้
คุณ arasked ต้องส่ง ตัวแปร year month day เหล่านี้ไปด้วยนะครับ
$_SERVER[SCRIPT_NAME]?Page ต่อท้ายจากนี่ครับ ขี้เกียจแก้ให้อะ แต่ถ้าเอาโค๊ดผมไปลองแก้ดู ผมว่ามันไม่น่าจะต้องเขียน Paging ใหม่ทุกหน้านะครับ
|
 |
 |
 |
 |
Date :
2010-03-17 02:10:13 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สุดยอ
|
 |
 |
 |
 |
Date :
2010-03-30 11:55:06 |
By :
Skeawkla |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามรูปนะครับ ตอนนี้ข้อมูลเริ่มเยอะทำให้เลขจำนวนหน้าเพิ่มขึ้นเรื่อยๆ

อยากสอบถามว่าถ้าทำแบบนี้จะได้ใหม ขอคำแนะนำ จะได้ส่งโค๊ตให้ดูครับ

ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-07-02 11:20:00 |
By :
numsai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แน่นอนครับ ก่อนอื่นลองเอาฟังก์ชั่นนี้ไปปรับใช้ดูก่อน ถ้าคุณเข้าใจ เรื่องมันแค่สิวๆ
|
 |
 |
 |
 |
Date :
2010-07-03 00:33:09 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ได้แล้วครับ
หาเพื่อนคุยmsn ตัวอย่าง
|
 |
 |
 |
 |
Date :
2010-07-03 23:04:46 |
By :
numsai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าแบ่งหน้าเสร็จแล้ว แต่อยากทำให้จำนวนลิงค์ไม่ยาวมากเหมือนข้างบนใช้โค้ดนี้ได้ครับ
pager adaptor
|
 |
 |
 |
 |
Date :
2010-10-22 18:41:49 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับใช้งานง่าย ผมมาแก้ไขแปลบเดียวใช้งานได้
|
 |
 |
 |
 |
Date :
2010-10-23 17:53:11 |
By :
kang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ ที่นำเอาความรู้มาเผยแพร่ ^_^
|
 |
 |
 |
 |
Date :
2011-01-06 17:13:33 |
By :
razencmm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากมาย(อย่างแรง)
|
 |
 |
 |
 |
Date :
2011-01-26 09:33:49 |
By :
hwungnee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<body>
<?
include"../connect.php";
$tblname="job";
$sql="select * from $tblname";
$dbquery=mysql_db_query($dbname,$sql);
?>
<?
function page_navi($page, $limit, $range, $count, $send=NULL, $current_style="navi_on", $other_style="navi_out", $target="_self"){
$output = "";
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send .= (!empty($send))? "&" : NULL;
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
$output .= "<a href=\"?" . $send . "page=1\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>«</strong></a> ";
$output .= "<a href=\"?" . $send . "page=" . $navi_back . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>‹</strong></a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $current_style . "\"><strong><font color=\"" . $other_style . "\">$i</font></strong></a> ";
else
$output .= "<a href=\"?" . $send . "page=" . $i . "\" target=\"" . $target . "\" class=\"" . $other_style . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
$output .= "<a href=\"?" . $send . "page=" . $navi_next . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>›</strong></a> ";
if(($page+1) < $total)
$output .= "<a href=\"?" . $send . "page=" . $total . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>»</strong></a>";
}
if($navi_start>$navi_end)
$output .= "<a href=\"?" . $send . "page=" . $page . "\" target=\"" . $target . "\" class=\"" . $other_style . "\"><strong>$page</strong></a> ";
return $output;
}
?>
<form id="list_job" name="list_job" method="post" action="">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right"><a href="#">
<? echo "<a href=\"javascript:;\" onclick=\"window.open('../job.php','show','menubar=no,toolbar=no,location=no,scrollbars=no, status=no,resizable=no,width=450,height=430,top=200,left=350 ');\">";?><img src="../img/repair.png" alt="แจ้งซ่อม" width="64" height="64" border="0" /></a></td>
<td> </td>
<td><a href="../logout.php" target="_parent"onclick="return confirm('คุณต้องการออกจากระบบ')">
<img src="../img/exit.png" alt="ออกจากระบบ" width="64" height="64" border="0" /></a></td>
</tr>
</table>
<p> </p>
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right"><img src="../img/wait.png" width="22" height="22" /> = รออนุมัติการซ่อม <img src="../img/approve.png" width="22" height="22" /> = อนุมัติการซ่อม <img src="../img/not_approve.png" width="22" height="22" /> = ไม่อนุมัติการซ่อม <img src="../img/make.png" width="22" height="22" /> = อยู่ระหว่างการซ่อม <img src="../img/ok.png" width="22" height="22" />= ซ่อมเสร็จแล้ว <img src="../img/no.png" width="22" height="22" /> = ซ่อมไม่ได้</td>
</tr>
</table>
<table width="950" border="1" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="43" align="center" bgcolor="#00CC33"><strong>ลำดับ</strong></td>
<td width="177" align="center" bgcolor="#00CC33"><strong>ชื่อ-สกุลผู้แจ้ง</strong></td>
<td width="72" align="center" bgcolor="#00CC33"><strong>แผนก</strong></td>
<td width="90" align="center" bgcolor="#00CC33"><strong>วัน เดือน ปี เวลาที่แจ้ง</strong></td>
<td width="78" align="center" bgcolor="#00CC33"><strong>ชื่ออุปกรณ์</strong></td>
<td width="251" align="center" bgcolor="#00CC33"><strong>อาการเสีย</strong></td>
<td width="44" align="center" bgcolor="#00CC33"><strong>สถานะ</strong></td>
<td width="78" align="center" bgcolor="#00CC33"><strong>การอนุมัติ</strong></td>
<td width="79" align="center" bgcolor="#00CC33"><strong>รายละเอียด</strong></td>
</tr>
<tr>
<?
$hostname="localhost";
$username="root";
$password="root";
$dbname="computer_service";
$conn = mysql_connect($hostname,$username,$password) or die ("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die ("เลือกฐานข้อมูลไม่ได้");
mysql_query("set names utf8",$conn);
mysql_query("USE computer_service");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 10;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE job_id = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM job" . $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $conn);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $conn));
if($total > 0){
$i=0;
while($result = mysql_fetch_assoc($query_id)){
$i++;
?>
<td align="center"><?= $i; ?></td>
<td>
<?
$user = $result["user"];
$sql ="select * from user where user_id='$user' ";
$query= mysql_query($sql);
$num = mysql_num_rows($query);
while($result_user = mysql_fetch_array($query))
{
?>
<?= $result_user["user_title"]; ?> <?= $result_user["user_name"]; ?> <?= $result_user["user_surname"]; ?> <? } ?></td>
<td>
<?
$dep = $result["dep_tel"];
$sql ="select * from dep where dep_tel='$dep' ";
$query= mysql_query($sql);
$num = mysql_num_rows($query);
while($result_dep = mysql_fetch_array($query))
{
?>
<?= $result_dep["dep_name"];?> <? } ?></td>
<td align="center"><?= $result[date]?> <?= $result[time]?></td>
<td align="center"><?= $result[device]?></td>
<td>
<?= $result_sym["sym_name"]; ?> <? } ?> <?= $result[symptom_other] ?></td>
<td align="center"></td>
<td align="center">แก้ไขสถานะ</td>
<td align="center"></td>
</tr>
<?
}
}
?>
</table>
</p>
<?
echo "<div align='center'>Page : " . page_navi($page, $limit_end, 4, $total, $send) . " </div><div align='center'>[ " . ($limit_start+1) . "-" . ($limit_start+$count) . "] " . $total . " </div>";
mysql_close();
?>
</form>
</body>
|
ประวัติการแก้ไข 2011-02-08 00:09:06 2011-02-10 00:14:20 2011-02-10 01:49:15
 |
 |
 |
 |
Date :
2011-02-07 23:16:10 |
By :
MOO PHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นั่งดูแล้วตาลาย ไม่ได้ปิด while($result=mysql_fetch_array($dbquery) ){ ครับ
|
 |
 |
 |
 |
Date :
2011-02-08 01:39:46 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ตอนนี้ติดตรงที่พอคลิกไปที่หน้า 2 มันจะเริ่มนับ 1 ใหม่ครับพี่ มันไม่เป็น 11 อ่ะครับพี่
|
 |
 |
 |
 |
Date :
2011-02-10 01:21:27 |
By :
MOO PHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ ช่วยได้เยอะเลย ^^
|
 |
 |
 |
 |
Date :
2011-04-01 01:10:41 |
By :
zimmpooh |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สวดยอดไปเลยครับโค๊ดนี้ เมื่อคืนมาดูอย่าง งง ตอนเช้ามาดูใหม่ ได้ซะงั้น (สงสัยสมาธิจะไปอยู่กับอย่างอื่นมากกว่า 555+)
ผมขอถามอีกนิดครับ ตัวแปรไหนเก็บค่า จำนวนหน้าทั้งหมด ไว้อะครับ
|
ประวัติการแก้ไข 2011-04-24 14:00:36 2011-04-24 14:00:49
 |
 |
 |
 |
Date :
2011-04-24 13:55:40 |
By :
thekknd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบ thekknd
$total = ceil($count/$limit);
ตอบ MOO PHP
$i=$start+1;
|
 |
 |
 |
 |
Date :
2011-04-24 14:00:39 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับผม
|
 |
 |
 |
 |
Date :
2011-04-24 14:01:27 |
By :
thekknd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
PHP MySQL Pagination ทำแบ่งหน้าด้วย PHP กับ MySQL ย่อจำนวนหน้า ในกรณีที่มีจำนวนหน้าเยอะ ๆ
No.137
รบกวนพี่ๆ ช่วยดูให้หน่อยนะคับ
พอกดปุ่ม <<Previous มันจะไม่เลื่อนกลับทีละหน้า แต่มันจะกลับไปหน้าแรกเลย
ควรแก้ไขตรงไหนอ่ะคับ
|
 |
 |
 |
 |
Date :
2011-05-23 11:40:54 |
By :
อ๊อดอ๊อด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เย้ๆๆๆ แก้ได้แว้ว^^
|
 |
 |
 |
 |
Date :
2011-05-23 15:46:26 |
By :
oodd2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2011-05-23 22:21:53 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนพี่ PlaKriM ช่วยบอกวิธีการแยก โค้ด ออกเป็นไฟล์ คือ อยากให้โค้ด connect_dbอยู่ไฟล์นึง และ โค้ดclass_แบ่งหน้าอยู่อีกไฟล์นึงอ่ะคับ แล้วให้มันแสดงผลตามเดิม รบกวนด้วยนะคับ (มือใหม่หัดเขียน^^)
Code (PHP)
<?
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $url_next;
function Paginator()
{
$this->current_page = 2;
$this->mid_range =7;
$this->items_per_page = $this->default_ipp;
$this->url_next = $this->url_next;
}
function paginate()
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"".$this->url_next.$prev_page."\">« ย้อนกลับ</a> ":"<span class=\"inactive\" href=\"#\">« ย้อนกลับ</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 2)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 2;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " .... ";
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$this->url_next.$i."\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-0]) $this->return .= "....";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">ถัดไป »</a>\n":"<span class=\"inactive\" href=\"#\" >ถัดไป»</span>\n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"".$this->url_next.$i."\">$i</a> ";
}
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_pages()
{
return $this->return;
}
}
?>
<html>
<head>
<title>LoginDatabase</title>
<style type="text/css">
<!--
.style1 {
color: #0000FF;
font-weight: bold;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("testlogin");
$strSQL = "SELECT * FROM login ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$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 Username ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="1000" border="1">
<tr>
<th width="184"> <div align="center" class="style1">ชื่อเข้าใช้</div></th>
<th width="195"> <div align="center" class="style1">รหัสผ่าน</div></th>
<th width="242"> <div align="center" class="style1">ชื่อ-สกุล</div></th>
<th width="195"> <div align="center" class="style1">จังหวัด</div></th>
<th width="150"> <div align="center" class="style1">อาชีพ</div></th>
</tr>
<?
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
if($i%2==0)
{
$bg = "#255FF255";
}
else
{
$bg = "#255FFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center"><?=$objResult["Username"];?>
</div></td>
<td><div align="center"><?=$objResult["Password"];?>
</div></td>
<td><div align="center"><?=$objResult["Name"];?>
</div></td>
<td><div align="center"><?=$objResult["Province"];?>
</div></td>
<td><div align="center"><?=$objResult["job"];?>
</div></td>
</tr>
<?
}
?>
</table>
<br>
ทั้งหมด <?= $Num_Rows;?> แถว : <?=$Num_Pages;?>
หน้า :
<?
$pages = new Paginator;
$pages->items_total = $Num_Rows;
$pages->mid_range = 10;
$pages->current_page = $Page;
$pages->default_ipp = $Per_Page;
$pages->url_next = $_SERVER["PHP_SELF"]."?QueryString=value&Page=";
$pages->paginate();
echo $pages->display_pages();
?>
<?
mysql_close($objConnect);
?>
</body>
</html>
|
ประวัติการแก้ไข 2011-05-24 11:33:58
 |
 |
 |
 |
Date :
2011-05-24 10:42:27 |
By :
อ๊อดอ๊อด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ยากนิครับ แค่แยก ตัวนี้ไปไฟล์นึง
Code (PHP)
<?
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $url_next;
function Paginator()
{
$this->current_page = 2;
$this->mid_range =7;
$this->items_per_page = $this->default_ipp;
$this->url_next = $this->url_next;
}
function paginate()
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"".$this->url_next.$prev_page."\">« ย้อนกลับ</a> ":"<span class=\"inactive\" href=\"#\">« ย้อนกลับ</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 2)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 2;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " .... ";
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['Page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$this->url_next.$i."\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-0]) $this->return .= "....";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['Page'] != 'All')) ? "<a class=\"paginate\" href=\"".$this->url_next.$next_page."\">ถัดไป »</a>\n":"<span class=\"inactive\" href=\"#\" >ถัดไป»</span>\n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"".$this->url_next.$i."\">$i</a> ";
}
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_pages()
{
return $this->return;
}
}
?>
นี่ไฟล์นึง
Code (PHP)
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("testlogin");
แล้ว include มา
|
 |
 |
 |
 |
Date :
2011-05-24 11:30:37 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ..มีประโยชน์มาก..จะลองทำดูครับ..
|
 |
 |
 |
 |
Date :
2011-05-24 11:48:59 |
By :
sarkhorn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้ครับ!!!! ขอบคุณมากๆคับP'PlaKriM แล้วจะทดลองดูครับ^^ (มือใหม่ อยากเขียน^^)
|
 |
 |
 |
 |
Date :
2011-05-24 11:49:31 |
By :
oodd2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สวดยอกเลยคับ พี่PlaKriM ทดลองแล้วประยุกต์แยกเป็น3ไฟล์ รันผ่านฉลุยก๊าฟฟฟ
ขอบคุณมากๆก๊าฟ อาจารย์ (มือใหม่อยากเขียน)
|
 |
 |
 |
 |
Date :
2011-05-24 14:28:57 |
By :
อ๊อดอ๊อด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ๊าาาาา มีปัญหามารบกวนอีกแว้ว ก๊าฟฟ พี่ PlaKriM ตามโค้ด NO.149
คือผมต้องการ ให้เรียงลำดับตัวอักษร จากน้อยไปมาก แต่จะให้เรียงโดย
1.Username
2.Password
3.Name
4.Province
5.job
คือเมื่อเลือก หรือ คลิ๊กตัวแปรใดมันก้อจากเรียงตามตัวแปรนั้น เช่น เลือก Name ก้อจะเรียงตาม Name ^^^ รบกวนด้วยนะคับ
(มือใหม่อยากเขียน) 
|
 |
 |
 |
 |
Date :
2011-05-25 12:30:32 |
By :
อ๊อดอ๊อด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องตั้งกระทู้ใหม่ถามพี่วินแหละครับงานนี้ น่าจะใช่โค๊ดพี่วิน
หลักการมันคือส่งพารามิเตอร์ไปพร้อมกับพารามิเตอร์เพจด้วย
|
 |
 |
 |
 |
Date :
2011-05-25 14:41:38 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อ ขอบคุณมากๆครับ พี่ PlaKriM 
|
 |
 |
 |
 |
Date :
2011-05-25 14:55:37 |
By :
อ๊อดอ๊อด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สวัสดีครับพี่ปลากริม
พอดีผมมีโค็ดโชว์หน้าแบบนี้
Code (PHP)
<HTML>
<HEAD>
<TITLE>รายการเคลมสินค้า</TITLE>
<HEAD>
<style type="text/css">
<!--
.style4 {color: #666666}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=TIS-620"></HEAD>
<style>
body {font-family:Microsoft Sans Serif ,MS Sans Serif ,Arial ,CordiaUPC ; font-size: 13px }
li,td {font-family : sans - serif , Arial ; font-size : 13px}
hr {color:#3333cc ; width = 700; text-align = left}
a.noline {COLOR: #ffffcc; TEXT-DECORATION: none }
a.noline:hover { COLOR: #99cc99}
a.cate {text-decoration:none; color: #333333;}
a.cate:hover {color:"cccccc";}
a.menu {text-decoration:none; color: "#6600FF";}
a.menu:hover {color:"#FF6600";}
a.shop {text-decoration:none;color: "#336600";}
a.shop:hover {color:"#FF6600";}
a.lmenu {color: "#000066"; text-decoration:none;}
a.lmenu:hover {color:"#FF6600"; text-decoration:none;}
.style1 {color: #333333}
.style3 {
color: #666666;
font-weight: bold;
}
</style>
<body background="images/nest.gif">
<table border="0" align="center">
<tr>
<td width="750"><img src="images/NSG1.jpg" width="750" height="176" border="0"></td>
</tr>
</table>
<div align="center" class="style2"><table width="757" border="0" bgcolor="#FFFFFF">
<tr >
<td></td>
<td width="75"><div align="center" class="style4"><p align="center">
<a class="cate" href="show_admin.php"><strong>หน้าหลัก</strong></a></p></div></td>
<td width="135"><div align="center" class="style4"><p align="center">
<a class="cate"href="look_admin.php"><strong> ข้อมูลผู้ดูแลระบบ </strong></a></p></div></td>
<td width="114"><div align="center" class="style4"><p align="center">
<a class="cate"href="look_emp.php"><strong> ข้อมูลพนักงาน</strong></a></p></div></td>
<td width="178"><div align="center" class="style4"><p align="center">
<a class="cate"href="look_cliams_admin.php"><strong> ข้อมูลการส่งเคลมสินค้า</strong></a></p></div></td>
<td width="108"><div align="center" class="style4"><p align="center">
<a href="index.php" class="cate"><strong>ออกระบบ</strong></a></p></div></td>
</tr>
</table></div>
<CENTER>
<p class="style3"> </p>
<p class="style3"><img src="images/News.png" width="51" height="51">รายการสินค้าส่งเคลม</p>
</CENTER>
<BR><BR>
<?
$db="nsg";
$tb="tb_cliams";
mysql_connect("localhost","root","1234") or die ("เรียกใช้ฐานข้อมูลไม่สำเร็จ");
mysql_select_db($db) or die("ติดต่อฐานข้อมูลไม่สำเร็จ");
mysql_query("set names TIS620");
$sql="select * from $tb order by num_s";
$db_query = mysql_db_query($db,$sql) ;
$num_rows=mysql_num_rows($db_query);
echo"<CENTER><TABLE border=1>";
echo"<TR bgcolor=#999999><TD>เลขที่บริการ</TD><TD>เล่มที่</TD><TD>วันที่บริการ</TD>
<TD>วันที่ส่งคืนสินค้า</TD><TD>วันที่บันทึกข้อมูล</TD><TD> ชื่อบริษัท</TD>
<TD> ที่อยู่บริษัทส่งคืน</TD><TD> ประเภทผลิตภัณฑ์</TD><td>ชื่อผลิตภัณฑ์</td>
<td>รุ่น</td><td>หมายเลขผลิตภัณฑ์</td><td>อุปกรณ์ที่ติดมาด้วย</td>
<td>ประกัน</td><td>รายละเอียด/อาการ</td><td>ชื่อผู้บันทึก</td><td>ตัวเลือก</td></TR>";
for($i=1 ; $i <=$num_rows;$i++){
$result=mysql_fetch_array($db_query);
$num_s=$result[num_s];
$time_ser=@date("d/m/Y",$result[time_ser]);
$time_ser_popup=@date("d/m/Y",$result[time_ser_popup]);
$time_save=$result[time_save];
$name_ser=$result[name_ser];
$name_add=$result[name_add];
$vol_s=$result[vol_s];
$pro_type=$result[pro_type];
$pro_name=$result[pro_name];
$version=$result[version];
$s_num=$result[s_num];
$device=$result[device];
$pro_insu=$result[pro_insu];
$pro_detail=$result[pro_detail];
$name=$result[name];
echo"<TR><TD>".$num_s."</TD><TD>".$vol_s."</TD><TD>".$time_ser."</TD><TD>".$time_ser_popup."</TD><TD>".$time_save."</TD><TD>".$name_ser."</TD><TD>".$name_add."</TD><TD>".$pro_type."</TD><TD>".$pro_name."</TD><TD>".$version."</TD><TD>".$s_num."</TD><TD>".$device."</TD><TD>".$pro_insu."</TD><TD>".$pro_detail."</TD><TD>".$name."</TD><TD>";
?>
<a href='look_cliams_del_admin.php?num_s=<?echo $num_s ;?>' onClick='return confirm("ต้องการลบข้อมูลสินค้ารับซ่อมเลขที่ <?echo $num_s ;?> ใช่หรือไม่")'><img src="images/delete.gif" width="16" height="16" border="0" alt="Delete"></a>
<?
echo "| <A HREF=look_cliams_edit_admin.php?num_s=$num_s><img src='images/edit.gif' width='30' height='15' border='0' alt='Edit'></A></TD></TR>"
;
}
echo"</TABLE></CENTER>";
?>
<table border="0" align="center">
<tr>
<td width="750">
<p><img src="images/NSG2.jpg" width="750" height="100" border="0"></p> </td>
</tr>
</table>
</BODY>
</HTML>
ผมต้องการจะโชว์ page ละ 20 ผมลองนำโค็ดไปทำดูรู้สึกว่างงมาก พี่ช่วยหน่อยนะครับ
ขอบคุณล่วงหน้าครับ ( มือใหม่ครับพี่ )
|
ประวัติการแก้ไข 2011-05-26 00:31:52 2011-05-26 00:39:13
 |
 |
 |
 |
Date :
2011-05-26 00:29:37 |
By :
dakzanarak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรงไหนคือโค๊ดแบ่งหน้าครับ ไม่เห็น ลองเอาโค๊ดผมไปลองปรับดู มีตัวอย่างด้วยลองทำดูก่อนครับ ทำแล้วติดค่อยว่ากัน
|
 |
 |
 |
 |
Date :
2011-05-26 01:02:59 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้แล้วครับ ขอบคุณมากครับพี่
|
 |
 |
 |
 |
Date :
2011-05-27 22:59:06 |
By :
dakzanarak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดีครับ เก่ง 
|
 |
 |
 |
 |
Date :
2011-05-27 23:59:04 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..............................
|
 |
 |
 |
 |
Date :
2012-02-15 05:42:35 |
By :
ther10 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูโค้ดให้หน่อยคร๊าบบบบบบบบบบ ที่แบ่งหน้า โค้ดประมาณนี้ครับ
<?
$strQuery="select top 96 convert(varchar(16),(DT + TM),120) as namevalue,$type as typevalue FROM [SONGKHAM].[dbo].[DATA_15MIN_RF_WL] where STN_ID='$station'";
$result = odbc_exec($link,$strQuery);
$Num_Rows = odbc_num_rows($result);
$Per_Page = 24;
$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;
}
//$strQuery .=" order by ID ASC LIMIT $Page_Start , $Per_Page";
$result = odbc_exec($link,$strQuery);
?>
<td width="100" align="center" bgcolor="#808080"><strong>ลำดับที่</strong></td>
<td width="200" align="center" bgcolor="#808080"><strong>วัน - เวลา</strong></td>
<td width="200" align="center" bgcolor="#808080"><strong> <? echo $yaname ?> </strong></td>
</tr>
<?
if ($result)
{
$no = 1 ;
if($Page > 1)
{
$no = ($Per_Page * ($Page-1))+1;
}
while($ors=odbc_fetch_array($result))
{
?>
<tr>
<td width="100" ><div align="center"> <?=$no;?> </div></td>
<td width="200" ><div align="center"><?=$ors['namevalue']?></div></td>
<td width="200" ><div align="center"><?=$ors['typevalue']?></div></td>
</tr>
<?
$no++;
}
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< ย้อนกลับ</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
$Page1 = $Page-2;
$Page2 = $Page+2;
if($i != $Page && $i >= $Page1 && $i <= $Page2)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
elseif($i==$Page)
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Num_Pages&txtKeyword=$_GET[txtKeyword]'>... Next>></a> ";
}
odbc_close($link);
?>

|
 |
 |
 |
 |
Date :
2012-02-21 17:17:01 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วครับ มันก็ยังไม่ได้ ผมเอาโค้ดที่เขียนใหม่มาให้ดูด้วยครับบ
Code (PHP)
$Per_Page = 24;
$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;
}
//$strQuery .=" order by ID ASC LIMIT $Page_Start , $Per_Page";
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}
$result = odbc_exec($link,$strQuery);
?>
<!-- <td width="100" align="center" bgcolor="#808080"><strong>ลำดับที่</strong></td>-->
<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++)
{
//if ($result)
//{
//$no = 1 ;
//if($Page > 1)
//{
//$no = ($Per_Page * ($Page-1))+1;
//}
while($ors=odbc_fetch_array($result))
{
?>
<tr>
<!-- <td width="100" ><div align="center"> <?=$no;?> </div></td> -->
<td width="200" ><div align="center"><?=$ors['namevalue',$i];?></div></td>
<td width="200" ><div align="center"><?=$ors['typevalue',$i];?></div></td>
</tr>
<?
//$no++;
}
}
?>
</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> ";
}
|
 |
 |
 |
 |
Date :
2012-02-22 11:15:40 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอถามอีกข้อครับบบบบ เกี่ยวกับตัว Highstock ซึ่งแสดงข้อมูลเป็นแบบกราฟเส้น คือผมติดปัญหาตรงที่กราฟมันไม่ขึ้นครับ
Code (PHP)
หน้า index.php
<!DOCTYPE HTML>
<html>
<head >
<meta http-equiv=Content-Type content="text/html; charset=windows-874">
<title>Highstock Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="./js/highstock.js"></script>
<script type="text/javascript" src="./js/modules/exporting.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON('http://127.0.0.1:89/Highstock/data.php?filename=usdeur.json&callback=?'
,function(data) {
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container'
},
rangeSelector: {
buttons: [{
type: 'day',
count: 1,
text: 'day'
}, {
type: 'week',
count: 1,
text: 'week'
}, {
type: 'month',
count: 1,
text: 'month'
},
{
type: 'year',
count: 1,
text: '1y'
}],
selected: 2
},
title : {
text : ''
},
yAxis : {
title : {
text : ''
},
},
series : [{
name : '',
data : data,
tooltip : {
yDecimals : 2
}
}]
});
});
});
</script>
</head>
<body>
<? include("list_radio.php"); ?>
<form name="form" action="" method="get" >
<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" type="radio" value="RF_15MIN" <?php if($type == "RF_15MIN") { echo"checked";} ?> >ปริมาณน้ำฝน </div>
<div> <input name="type" type="radio" value="WL_IN" <?php if($type == "WL_IN") { echo"checked";} ?> >ระดับน้ำ </div>
<div> <input name="type" type="radio" value="FLOW_IN" <?php if($type == "FLOW_IN") { echo"checked";} ?> >ปริมาณน้ำ </div>
</div>
<div> <input type="submit" name="Search" id="Search" value="ค้นหาข้อมูล"> </div>
<div id="container" style="height: 500px; min-width: 500px"></div>
</form>
</body>
</html>
----------- data.php --------------
<?
//header('filename="' . $_REQUEST['filename'] . '"');
echo $_REQUEST['callback'];
$link = odbc_connect ("SONGKHAM", "sa", "software");
if (!$link) {
die('Could not connect: ' . odbc_error());
}
//$type = $_GET['type'];
//$station = $_GET['station'];
//if ($_GET['type'] == $type && $_GET['station'] == $station)
$strQuery="select convert(varchar(16),(DT + TM),121) as namevalue,$type as typevalue FROM [SONGKHAM].[dbo].[DATA_15MIN_RF_WL]
where STN_ID='$station' ";
$result = odbc_exec($link,$strQuery);
$data = array();
while($ors=odbc_fetch_array($result))
{
$time1 = strtotime($ors['namevalue']);
$time=(string) $time1*1000;
$value = floatval($ors['typevalue']);
$data[] = array($time, $value);
}
echo '(';
echo json_encode($data);
echo ');';
?>

|
 |
 |
 |
 |
Date :
2012-02-22 14:45:41 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
rep. 164
ลองดูบทเรียนที่ผมแปะลิงค์ให้ใหม่นะครับ นี่ผมไม่เห็นมีการ query ตรงไหนเลย
rep. 165
ไม่รู้จะช่วยยังไงแหละครับ เปิดใน firefox แล้ว crtl+shit+j ดูครับ เผื่อมี javascript error อยู่
ถ้ายังไม่ได้ ไปตั้งกระทู้ใหม่นะครับ จะได้มีคนช่วยตอบ
|
 |
 |
 |
 |
Date :
2012-02-22 14:52:18 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษนะครับที่ถามเรื่อง ที่ไม่เกี่ยวกับ Forum
|
 |
 |
 |
 |
Date :
2012-02-22 15:20:21 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2012-02-22 15:21:52 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัว query ครับ
$strQuery="select top 672 convert(varchar(16),(DT + TM),120) as namevalue,$type as typevalue FROM [SONGKHAM].[dbo].[DATA_15MIN_RF_WL] where STN_ID='$station' ";
$result = odbc_exec($link,$strQuery);
<tr>
<!-- <td width="100" ><div align="center"> <?=$no;?> </div></td> -->
บรรทัดที่ 113 <td width="200" ><div align="center"><?=odbc_result($result,$i,"namevalue");?></div></td>
บรรทัดที่ 114 <td width="200" ><div align="center"><?=odbc_result($result,$i,"typevalue");?></div></td>
</tr>
มันบอก
EROR แบบนี้ครับ
Warning: Wrong parameter count for odbc_result() in C:\AppServ\www\PowerCharts_Enterprise\rowpage.php on line 113
Warning: Wrong parameter count for odbc_result() in C:\AppServ\www\PowerCharts_Enterprise\rowpage.php on line 114
|
 |
 |
 |
 |
Date :
2012-02-22 15:26:08 |
By :
DEKLAO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนตั้งกระทู้ใหม่ครับ error นั่นน่าจะเกิดจาก result resource มันไม่มีครับ
|
 |
 |
 |
 |
Date :
2012-02-22 15:31:40 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือตอนนี้แบ่งหน้าได้แสดงข้อมูลได้คับ แต่ว่าจะไปหน้า 2 3 4 ที่เหลือไม่ได้ เหมือนกับ URL มันชี้ไปผิดซึ่งตอนแรกจะเป็น
http://localhost/๊User/management/index.php?menu=person คับ แสดงข้อมูล 10 แถว
แต่พอไปดูหน้า 2 มันกลายเป็น
http://localhost/captain2/management/index.php?page=2
ซึ่งเด้งกลับไปหน้า index เลย
ต้องแก้ code ยังไงอ่าคับ ผมนั่งดูมา ตั้งแต่เมื่อวานเที่ยงจนถึงตอนนี้ยังแก้ไม่ได้เลย T T ขอความกรุณาด้วยคับ
Code (PHP)
<?php
#######################################################################
# $page = (isset($_GET['page']))? intval($_GET["page"]) : 0;
# $limit_end = 20;
# $limit_start = ($page-1)*$limit_end;
# $sql = "select * from table limit " . $limit_start. "," . $limit_end;
# page_navi($page, $limit_end, 4, 1000, "_self", "current_page", "other_page", $querystring);
#######################################################################
# $page = หน้าปัจจุบัน
# $limit= จำนวน record ต่อหน้า
# $range= บวกลบจากหน้าปัจจุบัน ใส่ 4 จะได้ตัวเลขออกมา 9
# $count= จำนวน record ทั้งหมด
# $target= อันนี้รู้ๆ กัน
# $current_style = css สำหรับ navi
# $quetystring= ส่งตัวแปรอะไรไปด้วย
#######################################################################
function page_navi($page, $limit, $range, $count, $target="_self", $current_style="", $other_style="", $quetystring=""){
$total = ceil($count/$limit);
$navi_start = $page-$range;
$navi_end = $page+$range;
$send = !empty($querystring)? "&". $querystring : "";
if($navi_start <= 0) $navi_start = 1;
if($navi_end >= $total) $navi_end = $total;
if($page>1){
$navi_back = $page-1;
if($page > 2)
echo "<a href=\"?page=1" . $send . "\" target=\"" . $target . "\">«</a> ";
echo "<a href=\"?page=$navi_back" . $send . "\" target=\"" . $target . "\">‹</a> ";
}
for($i = $navi_start; $i <= $navi_end; $i++){
if($i == $page)
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
else
echo "<a href=\"?page=$i" . $send . "\" target=\"" . $target . "\">$i</a> ";
}
if($page < $total){
$navi_next = $page+1;
echo "<a href=\"?page=$navi_next" . $send . "\" target=\"" . $target . "\">›</a> ";
if(($page+1) < $total)
echo "<a href=\"?page=$total" . $send . "\" target=\"" . $target . "\">»</a>";
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=TIS-620">
<link href="style.css" rel="stylesheet" type="text/css" />
<form method="post" name="form1">
<input type="submit" name='person' value="add" class="submit-add" title="เพิ่ม">
<input type="submit" name='person' value="edit" class="submit-edit" title="แก้ไข" onclick="return checkform()">
<input type="submit" name='person' value="delete" class="submit-del" title="ลบ" onclick="return checkform()">
<table width="100%" style="float:left;">
<tr class="th" >
<td width="2%" >#</td>
<td width="7%" >เลขที่</td>
<td width="7%" >ยศ</td>
<td width="10%" >ชื่อเล่น</td>
<td width="20%" >ชื่อ</td>
<td width="9%" >เบอร์โทรศัพท์</td>
<td width="40%" >ที่อยู่</td>
</tr>
<?php
$hostNameDB = "localhost";
$userNameDB = "root";
$passWordDB = "1234";
//$conn = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
$conn = mysql_connect($hostNameDB, $userNameDB, $passWordDB) or die ("Cannot connect to Server or connect person Database");
mysql_query("SET NAMES tis620", $conn);
mysql_query("USE captain2");
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 10;
$limit_start = ($page-1)*$limit_end;
$send = "";
if(isset($_GET["id"]) and $_GET["id"] != ""){
$send = "id=" . $_GET["id"];
$condition= " WHERE id = '" . $_GET["id"] . "'";
}
$sql = "SELECT * FROM person order by id". $condition;
$query_id = mysql_query($sql . " LIMIT " . $limit_start. "," . $limit_end, $conn);
$count = mysql_num_rows($query_id);
$total = mysql_num_rows(mysql_query($sql, $conn));
if($total > 0){
while($re = mysql_fetch_assoc($query_id)){ ?>
<tr class="<? if($j % 2){ echo "tdetail";}else{echo "tdetail2";}?>">
<td height="39"><input type="checkbox" name="id[]" value="<?=$re["id"];?>"></td>
<td ><?=$re["number"];?></td>
<td ><?=$re["rank"];?></td>
<td ><?=$re["nick_name"];?></td>
<td ><?=$re["first_name"].' '.$re["last_name"];?></td>
<td ><?=$re["phone"]?></td>
<td ><?=$re["address"];?></td>
</tr>
<?
}
echo "\n<div style=\"float:left;\">Page : " . page_navi($page, $limit_end, 18, $total, "current_page","other_page",$send) . " </div><div style=\"float:right;\">[" . ($limit_start+1) . " - " . ($limit_start+$count) . "] of <strong>" . $total . "</strong></div>";
}
?>
</html>
|
 |
 |
 |
 |
Date :
2012-05-18 13:06:55 |
By :
Make |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|