Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > แบ่งหน้า แล้ว รันตัวเลขลำดับ ข้างหน้า แต่ หน้าแรก รับออกทุกแถวค่ะ


[PHP] แบ่งหน้า แล้ว รันตัวเลขลำดับ ข้างหน้า แต่ หน้าแรก รับออกทุกแถวค่ะ

 
Topic : 112066



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์



ฐานข้อมูลมีทั้งหมด ๗ แถว  ออกมาหมด

ฐานข้อมูลมีทั้งหมด ๗ แถว  ๔ เพราะออกไปแล้วในหน้าแร


ฐานข้อมูลมีทั้งหมด ๗ แถว  หน้า ๓ เหลือ ๑



Tag : PHP, MySQL

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-10-20 22:13:48 By : kabill View : 1564 Reply : 3
 

 

No. 1



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body,td,th {
font-family: mS Sans Serif, microsoft Sans Serif, tahoma;
font-size: 9pt;
}
-->
</style>

<style type="text/css">
<!--
body,td,th {
font-family: mS Sans Serif, microsoft Sans Serif;
font-size: 11pt;
}
a:link { TEXT-DECORATION: none; color: #3F7CB9}
a:visited { text-decoration: none;color: #3399FF}
a:hover { text-decoration: none;color: #FF9900}

-->
</style>

</head>

<body topmargin="0">

<table width="500" border="0" cellspacing="1" cellpadding="3">


<tr>
<td><table width="90%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td><table width="90%" border="0" cellspacing="0" cellpadding="0">
<!-- <tr>
<td>&nbsp;</td>
</tr> -->
<?php

include("db_conf.inc.php");
include("compare_date.php");

$now_year=date("Y");
$now_date=date("/m/d");

if($now_year>2500){
$now_year=$now_year-543;
}

$now_date=$now_year.$now_date;

mysql_connect($hostname,$user,$password);
include("charset.inc.php");



?>
</table></td>
</tr>
<tr>
<!-- <td>...........................</td> -->
</tr>
<tr>
<td height="20">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
echo "<br>";
//mysql_connect($hostname,$user,$password);

$sql = "select * from viannews where newsstyle='1' and status='1' ";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");

$num_rows = mysql_num_rows($db_query);


$ii=1;
$Per_Page = 3; // 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_rows =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;
}



$i=1;
$j=1;
//if($num_rows>0){


if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1;
}

$sql .= " order by postdate desc ,id desc LIMIT $Page_Start , $Per_Page";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");



if($num_rows>0){
//echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><img src=\"pict49/app_banner01-1.jpg\" width=\"250\" height=\"30\"></div></td></tr>";
echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><font size=\"3\" face=\"Ms Sans Serif\" color=\"#CC0000\">+ + ฝ่ายบริหารทั่วไป</br></br></font></div></td></tr>";
}






while($i<$num_rows){ // อ่านข้อมูลแต่ละเรกคอร์ด
$result = mysql_fetch_array($db_query);
$nheader = $result[nheader];
$booknumber = $result[booknumber];
$nfile1 = $result[nfile1];
$nfile2 = $result[nfile2];
$nfile3 = $result[nfile3];
$nfile4 = $result[nfile4];
$nlink1 = $result[nlink1];
$nlink2 = $result[nlink2];
$nlink3 = $result[nlink3];
$postdate = $result[postdate];
$optionshow = $result[optionshow];

$countfile=0;
$countlink=0;
$str_tmp="";

if($nfile1!=""){
$countfile++;
}
if($nfile2!=""){
$countfile++;
}
if($nfile3!=""){
$countfile++;
}
if($nfile4!=""){
$countfile++;
}

if($countfile>1){
$runfile=1;
}
else{
$runfile="";
}

if($nlink1!=""){
$countlink++;
}
if($nlink2!=""){
$countlink++;
}
if($nlink3!=""){
$countlink++;
}

if($countlink>1){
$runlink=1;
}
else{
$runlink="";
}


echo "<tr >";



echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$i</font></div>";

echo "<td valign=\"top\"><font size=\"3\"><div align=\"left\">$nheader </div></font>";
echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$booknumber</font></div>";

if($nfile1!=""){
echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><a href=\"ocn_news/file/$nfile1\" target=\"_blank\"><font size=\"3\" color=\"#0066FF\">รายละเอียด $runfile </font></a></td>";
$str_tmp=" | ";
$runfile++;
}
if($nlink1!=""){
echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$str_tmp <a href=\"$nlink1\" target=\"_blank\"><font size=\"2\" color=\"#0066FF\">รายละเอียดเพิ่มเติม $runlink</font></a></td>";
$runlink++;
$str_tmp=" | ";
}

$tmp_caldate=calDate(seperateDate($postdate),seperateDate($now_date));
if($tmp_caldate<=7){
echo " <td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><img src=\"img/i_new.gif\" width=\"30\" height=\"10\"></td> ";

}









echo "</div></td>";
echo "</tr>";


$i++;

}
//echo "<br>";
//2 mysql_close();

?>
</table></td>
</tr>
</table></td>
</tr>
<!-- <tr>
<td>&nbsp;</td>
</tr> -->
</table>




<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Prev_Page'><< Back</a> ";
}

for($a=1; $a<=$Num_Pages; $a++){
if($a != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$a'>$a</a> ]";
}
else
{
echo "<b> $a </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Next_Page'>Next>></a> ";
}
mysql_close();
?>
</body>
</html>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-20 22:16:10 By : kabill
 

 

No. 2



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


ลองศึกษาดูนะครับ
และคราวหน้าช่วย เอา tag code ครอบด้วยนะครับ อยู่เหนือ textarea ขวามือนะครับ
Code (PHP)
001.<html>
002.<head>
003.<title>Untitled Document</title>
004.<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
005.<style type="text/css">
006.<!--
007.body,td,th {
008.font-family: mS Sans Serif, microsoft Sans Serif, tahoma;
009.font-size: 9pt;
010.}
011.-->
012.</style>
013. 
014.<style type="text/css">
015.<!--
016.body,td,th {
017.font-family: mS Sans Serif, microsoft Sans Serif;
018.font-size: 11pt;
019.}  
020.a:link { TEXT-DECORATION: none; color: #3F7CB9}
021.a:visited { text-decoration: none;color: #3399FF}
022.a:hover { text-decoration: none;color: #FF9900}
023.-->
024.</style>
025. 
026.</head>
027.<body topmargin="0">
028.<table width="500" border="0" cellspacing="1" cellpadding="3">
029.<tr><td>
030.    <table width="90%" border="0" cellspacing="0" cellpadding="5">
031.    <tr><td>
032.        <!--  tag table ข้างล่างนี้ สร้างมาเพื่ออะไรครับ -->
033.        <table width="90%" border="0" cellspacing="0" cellpadding="0">
034.<!-- <tr>
035.<td>&nbsp;</td>
036.</tr> -->
037.<?php
038. 
039.include("db_conf.inc.php");
040.include("compare_date.php");
041. 
042.$now_year=date("Y");
043.$now_date=date("/m/d");
044. 
045.if($now_year>2500){
046.    $now_year=$now_year-543;
047.}
048. 
049.$now_date=$now_year.$now_date;
050. 
051.mysql_connect($hostname,$user,$password);
052.include("charset.inc.php");
053. 
054.?>
055.        </table></td></tr>
056.        <tr>
057.        <!-- <td>...........................</td> -->
058.        </tr>
059.        <tr><td height="20">
060.            <table width="100%" border="0" cellspacing="0" cellpadding="0">
061.<?php
062.echo "<br>"; // echo ทำไมครับ มันอยู่ใน tag table ไม่ได้มีประโยชน์อะไรเลย
063.//mysql_connect($hostname,$user,$password);
064. 
065./*
066.$sql = "select * from viannews where newsstyle='1' and status='1' ";
067.$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
068.$num_rows = mysql_num_rows($db_query);
069.*/
070.// 3 บันทัดบน เปลือง bandwidth สำหรับการ transfer ข้อมูล เปลี่ยนเป็นข้างล่าง
071.$sql = "select count(*) from viannews where newsstyle='1' and status='1' ";
072.$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
073.list($num_rows) = mysql_fetch_row($db_query); mysql_free_result($db_query);
074. 
075.$ii=1;
076.$Per_Page = 3; // Per Page
077. 
078./*
079.$Page = $_GET["Page"];
080.if(!$_GET["Page"])
081.{
082.$Page=1;
083.}
084.*/
085.// กำหนดค่า $Page ข้างบน จะมี warning ถ้าเรียกใช้ครั้งแรก
086.$Page = isset($_GET['Page'])? $_GET['Page'] : 1;
087. 
088. 
089.$Prev_Page = $Page-1;
090.$Next_Page = $Page+1;
091. 
092.$Page_Start = $Page * $Per_Page - $Per_Page; // หลักคณิตศาสตร์ คอมฯ ทำตามความสำคัญของ operator ที่สำคัญก่อน ไม่ต้องใส่วงเล็บก็ได้
093./*
094.if($num_rows<=$Per_Page)
095.{
096.$num_rows =1;
097.}
098.else if(($num_rows % $Per_Page)==0)
099.{
100.$Num_Pages =($num_rows/$Per_Page) ;
101.}
102.else
103.{
104.$Num_Pages =($num_rows/$Per_Page)+1;
105.$Num_Pages = (int)$Num_Pages;
106.}
107.*/
108.// ข้างบนมันอ้อมไปหรือเปล่าครับ
109.$Num_Page = ceil( $num_rows / $Per_Page); // หาจำนวนเพจทั้งหมด
110. 
111.$i=1;
112.$j=1;
113.//if($num_rows>0){
114. 
115. 
116.if($Page > 1)
117.{
118.$i = ($Per_Page * ($Page-1)) + 1;
119.}
120. 
121.// statement สำหรับ หา จำนวน record และ นำมาใช้งาน แยกกันชัดเจน เพราะใช้งานคนละอย่าง
122.$sql = "select * from viannews where newsstyle='1' and status='1' ";
123.$sql .= " order by postdate desc ,id desc LIMIT $Page_Start , $Per_Page";
124.$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
125. 
126.if($num_rows>0){
127.//echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><img src=\"pict49/app_banner01-1.jpg\" width=\"250\" height=\"30\"></div></td></tr>";
128.echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><font size=\"3\" face=\"Ms Sans Serif\" color=\"#CC0000\">+ + ฝ่ายบริหารทั่วไป</br></br></font></div></td></tr>";
129.}
130. 
131.//while($i<$num_rows){ // อ่านข้อมูลแต่ละเรกคอร์ด   
132.// while ข้างบน ที่ทำให้ แสดง จำนวนบันทัดทั้งหมด เพราะ $num_rows เป็นค่า จำนวนทั้งหมดของ การคิวรี่ ครั่งแรก
133.//$result = mysql_fetch_array($db_query)
134.// ไม่จำเป็นต้องใช้ fetch_array เพราะไม่ได้มีการอ้าง แบบ ลำดับที่ของ element ใช้ชื่อในการอ้าง
135.while( $result = mysql_fetch_assoc($db_query)){ // แบบนี้ชัดเจนว่าได้ result ตามต้องการแน่นอน ไม่มีบันทัดเกิน
136.    //$nheader = $result[nheader];  แบบนี้ไม่ควรเขียน ควรมี single quote ครอบขื่อ ฟีลด์ด้วย
137.    // มันไม่ error แต่มันมี warning ทำให้เครื่องทำงานหนักเพิ่มขึ้น
138./*
139.    $nheader = $result['nheader'];
140.    $booknumber = $result['booknumber'];
141.    $nfile1 = $result['nfile1'];
142.    $nfile2 = $result['nfile2'];
143.    $nfile3 = $result['nfile3'];
144.    $nfile4 = $result['nfile4'];
145.    $nlink1 = $result['nlink1'];
146.    $nlink2 = $result['nlink2'];
147.    $nlink3 = $result['nlink3'];
148.    $postdate = $result['postdate'];
149.    $optionshow = $result['optionshow'];
150.*/
151.    // ข้างบนเขียนยาวไป แต่ก็ถือว่าอ่านแล้วเข้าใจ แต่ลองลดรูปนะครับ
152.    extract($result); // คำสั่งนี้ทำแทนคำสั่งข้างบนนะครับ
153.    // สำหรับข้างล่างต่อไป ลองแก้เอาเองนะครับ
154.     
155.    $countfile=0;
156.    $countlink=0;
157.    $str_tmp="";
158.     
159.    if($nfile1!="") $countfile++;
160.    if($nfile2!="") $countfile++;
161.    if($nfile3!="") $countfile++;
162.    if($nfile4!="") $countfile++;
163.     
164.    if($countfile>1) $runfile=1; else $runfile="";
165.    if($nlink1!="") $countlink++;
166.    if($nlink2!="") $countlink++;
167.    if($nlink3!="") $countlink++;
168.     
169.    if($countlink>1) $runlink=1; else $runlink="";
170. 
171.    echo "<tr >";
172.    echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$i</font></div>";
173.    echo "<td valign=\"top\"><font size=\"3\"><div align=\"left\">$nheader </div></font>";
174.    echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$booknumber</font></div>";
175.     
176.    if($nfile1!=""){   
177.        echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><a href=\"ocn_news/file/$nfile1\" target=\"_blank\"><font size=\"3\" color=\"#0066FF\">รายละเอียด $runfile </font></a></td>";
178.        $str_tmp=" | ";
179.        $runfile++;
180.    }
181.    if($nlink1!=""){
182.        echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$str_tmp <a href=\"$nlink1\" target=\"_blank\"><font size=\"2\" color=\"#0066FF\">รายละเอียดเพิ่มเติม $runlink</font></a></td>";
183.        $runlink++;
184.        $str_tmp=" | ";
185.    }
186.     
187.    $tmp_caldate=calDate(seperateDate($postdate),seperateDate($now_date));
188.    if($tmp_caldate<=7){
189.        echo " <td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><img src=\"img/i_new.gif\" width=\"30\" height=\"10\"></td> ";
190.    }
191.     
192.    echo "</div></td>";
193.    echo "</tr>";
194.     
195.    $i++;
196. 
197.}
198.//echo "<br>";
199.//2 mysql_close();
200. 
201.?>
202.</table></td>
203.</tr>
204.</table></td>
205.</tr>
206.<!-- <tr>
207.<td>&nbsp;</td>
208.</tr> -->
209.</table>
210. 
211.<br>
212.Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
213.<?php
214.if($Prev_Page)
215.{
216.echo " <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Prev_Page'><< Back</a> ";
217.}
218. 
219.for($a=1; $a<=$Num_Pages; $a++){
220.if($a != $Page)
221.{
222.echo "[ <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$a'>$a</a> ]";
223.}
224.else
225.{
226.echo "<b> $a </b>";
227.}
228.}
229.if($Page!=$Num_Pages)
230.{
231.echo " <a href ='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Next_Page'>Next>></a> ";
232.}
233.mysql_close();
234.?>
235.</body>
236.</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-21 08:51:13 By : Chaidhanan
 

 

No. 3



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ คุณChaidhanan มากๆค๊าาา แล้วจะทบทวนทีละบรรทัดค๊าา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-10-21 08:57:30 By : kabill
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : แบ่งหน้า แล้ว รันตัวเลขลำดับ ข้างหน้า แต่ หน้าแรก รับออกทุกแถวค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่