|
 |
|
ช่วยดูหน่อยครับ ไม่ส่งค่า view.php?id_view=$id_news ไปครับ และยากให้ detail_news โชว์แค่สามบรรทัดต้องทำไงครับ บรรทัด 126 ครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
include"connect.php";
?>
<?php
// ส่วนของการกำหนดค่า
$setContainBox=500; // ความกว้างของพื้นที่เนื้อหา
$setNumColumn=2; //จำนวนคอลัมน์ที่ต้องการแสดง
$setNumRow=3; // จำนวนแถวที่ต้องการแสดง
$setHeightColumn=40; //ความสูงของแต่ละแถว
$setMarginColumn=2; // ระยะห่างระหว่างแถวและระหว่างคอลัมน์
$setWidthBorder=1; // ความกว้างเส้นขอบ
$setWidthColumn=($setContainBox/$setNumColumn)-(($setMarginColumn*$setNumColumn)+($setWidthBorder*$setNumColumn)*2);
?>
<!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" />
<title>learn mysql function</title>
<style type="text/css">
body{
font-size:12px;
}
/* css ส่วนตัวเลขแสดงการแบ่งหน้า */
.mynavi{
display:block;
width:25px;
height:20px;
text-align:center;
text-decoration:none;margin-right:3px;
background-color:#99CC33;
color:#FFFFFF;
float:left;
font-size:12px;
line-height:20px;
}
/* css ส่วนตัวเลขแสดงการแบ่งหน้า กรณีเมาส์ over หรืออยู่ในหน้านั้น */
.mynavi:hover,.mynavi_active{
display:block;
width:25px;
height:20px;
text-align:center;
text-decoration:none;margin-right:3px;
background-color:#000000;
color:#FFFFFF;
float:left;
font-size:12px;
line-height:20px;
}
/* css ส่วนกำหนดรายละเอียดจำนวนหน้า */
.pgnavi{
display:block;
height:25px;
font-size:12px;
line-height:20px;
float:left;
margin-left:50px;
margin-right:3px;
}
/* css ส่วนพื้นที่เนื้อหา มีการรับค่าจากตัวแปร PHP */
.showInColumn{
display:block;
list-style:none;
margin:0;
padding:0;
width:<?=$setContainBox?>px;
background-color:#FCC;
}
/* css ส่วนพื้นที่เนื้อหาลิสรายการ มีการรับค่าจากตัวแปร PHP */
.listColumn{
display:block;
margin:<?=$setMarginColumn?>px;
height:<?=$setHeightColumn?>px;
width:<?=$setWidthColumn?>px;
float:left;
border:<?=$setWidthBorder?>px solid #CCC;
}
</style>
</head>
<body>
<?php
// สร้างฟังก์ชั่น สำหรับแสดงการแบ่งหน้า
function page_navigator($before_p,$plus_p,$total,$total_p,$chk_page){
echo "<span class=pgnavi>".$before_p." to ".$plus_p." of ".$total." | Go to Page</span> ";
for($i=0;$i<$total_p;$i++){
$now_class=($chk_page==$i)?"mynavi_active":"mynavi";
echo "<a class='".$now_class."' href='?s_page=$i'>".intval($i+1)."</a> ";
}
}
?>
<?php
$q="select * from tb_news "; // แก้ไขขื่อตารางตามต้องการ
$qr=mysql_query($q);
$total=mysql_num_rows($qr);
$e_page=$setNumRow*$setNumColumn; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า
if(!isset($_GET['s_page'])){
$_GET['s_page']=0;
}else{
$chk_page=$_GET['s_page'];
$_GET['s_page']=$_GET['s_page']*$e_page;
}
$q.=" limit ".$_GET['s_page'].",$e_page";
$qr=mysql_query($q);
if(mysql_num_rows($qr)>=1){
$plus_p=($chk_page*$e_page)+mysql_num_rows($qr);
}else{
$plus_p=($chk_page*$e_page);
}
$total_p=ceil($total/$e_page);
$before_p=($chk_page*$e_page)+1;
?>
<?
mysql_set_charset("utf8",$link);
$i=1;
$q="select * from tb_news limit ".$_GET['s_page'].",$e_page"; // แก้ไขขื่อตารางตามต้องการ
$qr=mysql_query($q);
echo "<ul class='showInColumn'>";
while($rs=mysql_fetch_array($qr)){
?>
<A HREF='view.php?id_view=$id_news'TARGET='_blank'><li class='listColumn'><?=$rs['title_news']?></A><br/><?=$rs['detail_news']?></br>วันที่โพส <?=$rs['date_news']?><?php
}
echo "</ul>";
mysql_close($link);
?>
<br style="clear:both;" />
<br style="clear:both;" />
<?php
// เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า
page_navigator($before_p,$plus_p,$total,$total_p,$chk_page);
?>
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-06-04 10:48:16 |
By :
buraratn |
View :
1491 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่านแล้วไม่เข้าใจครับ เอาไปใช้ยังไงครับ
|
 |
 |
 |
 |
Date :
2011-06-04 11:49:26 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาแบบสั้นง่ายๆแหล่ะกันน่ะครับ
Code (PHP)
echo $text1 = iconv_substr($details,0,100)."<br />"; // ตัดสตริงตั้งแต่ตัวที่ 0 นับไปอีก 100 ตัว แบบนี้พอเข้าใจไม๊ครับ
echo $text1 = iconv_substr($details,101,200)."<br />";
echo $text1 = iconv_substr($details,201,300)."<br />";
// iconv_substr($details,201,300,UTF-8) // แบบนี้เป็นการระบุ encoding ให้ข้อความด้วยครับ
// แต่ความสมบูรณ์ของข้อความที่ตัดได้คงไม่ตรงใจเท่าไหร่น่ะครับ
|
ประวัติการแก้ไข 2011-06-04 20:59:12
 |
 |
 |
 |
Date :
2011-06-04 20:58:41 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก้ยังไม่ได้อยู่ดีครับ สงสัยใส่ไม่ถูกครับ 555
|
 |
 |
 |
 |
Date :
2011-06-05 01:39:00 |
By :
buraratn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|