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,027

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



 

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

 



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 : 1453 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,556 )
บทความ ( 2 )



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


ลองศึกษาดูนะครับ
และคราวหน้าช่วย เอา tag code ครอบด้วยนะครับ อยู่เหนือ textarea ขวามือนะครับ
Code (PHP)
<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>
		<!--  tag table ข้างล่างนี้ สร้างมาเพื่ออะไรครับ -->
		<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>"; // echo ทำไมครับ มันอยู่ใน tag table ไม่ได้มีประโยชน์อะไรเลย	
//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);
*/
// 3 บันทัดบน เปลือง bandwidth สำหรับการ transfer ข้อมูล เปลี่ยนเป็นข้างล่าง
$sql = "select count(*) from viannews where newsstyle='1' and status='1' ";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
list($num_rows) = mysql_fetch_row($db_query); mysql_free_result($db_query);

$ii=1;
$Per_Page = 3; // Per Page

/*
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
*/ 
// กำหนดค่า $Page ข้างบน จะมี warning ถ้าเรียกใช้ครั้งแรก
$Page = isset($_GET['Page'])? $_GET['Page'] : 1;


$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = $Page * $Per_Page - $Per_Page; // หลักคณิตศาสตร์ คอมฯ ทำตามความสำคัญของ operator ที่สำคัญก่อน ไม่ต้องใส่วงเล็บก็ได้
/*
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;
}
*/
// ข้างบนมันอ้อมไปหรือเปล่าครับ
$Num_Page = ceil( $num_rows / $Per_Page); // หาจำนวนเพจทั้งหมด

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


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

// statement สำหรับ หา จำนวน record และ นำมาใช้งาน แยกกันชัดเจน เพราะใช้งานคนละอย่าง
$sql = "select * from viannews where newsstyle='1' and status='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){ // อ่านข้อมูลแต่ละเรกคอร์ด	
// while ข้างบน ที่ทำให้ แสดง จำนวนบันทัดทั้งหมด เพราะ $num_rows เป็นค่า จำนวนทั้งหมดของ การคิวรี่ ครั่งแรก
//$result = mysql_fetch_array($db_query) 
// ไม่จำเป็นต้องใช้ fetch_array เพราะไม่ได้มีการอ้าง แบบ ลำดับที่ของ element ใช้ชื่อในการอ้าง
while( $result = mysql_fetch_assoc($db_query)){ // แบบนี้ชัดเจนว่าได้ result ตามต้องการแน่นอน ไม่มีบันทัดเกิน
	//$nheader = $result[nheader];  แบบนี้ไม่ควรเขียน ควรมี single quote ครอบขื่อ ฟีลด์ด้วย
	// มันไม่ error แต่มันมี warning ทำให้เครื่องทำงานหนักเพิ่มขึ้น
/*
	$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'];
*/
	// ข้างบนเขียนยาวไป แต่ก็ถือว่าอ่านแล้วเข้าใจ แต่ลองลดรูปนะครับ
	extract($result); // คำสั่งนี้ทำแทนคำสั่งข้างบนนะครับ
	// สำหรับข้างล่างต่อไป ลองแก้เอาเองนะครับ
	
	$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-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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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