่ช่วยแก้ปัญหา php ในการดึงข้อมูลมาโชว์หน่อยครับผม

เริ่มโดย Gaylydigg, 31 สิงหาคม 2011, 10:34:15

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Gaylydigg

$sql="select m.refno,m.category_id,c.category_detail,m.poptype_id,p.poptype_detail,";
$sql=$sql."m.location_id,l.location_detail,m.saleprice,m.rentprice,";
$sql=$sql."m.img1,m.img2,m.img3,m.img4,m.img5,m.landarea,m.livingarea,";
$sql=$sql."m.livingrooms,m.bedrooms,m.bathrooms,m.furnished,m.airconunits,m.name  from masterref m";
$sql=$sql." inner join category c on m.category_id=c.category_id ";
$sql=$sql." inner join poptype p on m.poptype_id=p.poptype_id ";
$sql=$sql." inner join location l on m.location_id=l.location_id ";
$sql=$sql." where m.category_id = '2' And p.poptype_id='2' ";
$sql =$sql." ORDER BY refno DESC LIMIT $start,$limit";

/////////////////////////////////////////////////////////////////


$tableName="category"; // เอา Table category มา
$targetpage = "house_sales.php";
$limit = 10;

$query = "SELECT COUNT(*) as num FROM $tableName"; // ตรงนี้อยากให้มันแสดงผลลัพท์ ของ $sql=$sql." where m.category_id = '2' And p.poptype_id='2' ";    category_id คือ id ของ category ส่วน poptype_id ก็คือ พวก sale บลาๆๆ ผลลัพท์ก็จะจะโชว์ บ้าน แต่ สำหรับ ขาย มีจำนวนเท่าไร
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

moomdede

กระเป๋าแฟชั่น & กระเป๋า handmade น่ารักๆ  http://www.moomfashion.com

marus

ต้องการแสดงจำนวนทั้งหมดหรือเปล่าถ้าใช้
แบบง่ายๆก็
$sql="select m.refno,m.category_id,c.category_detail,m.poptype_id,p.poptype_detail,";
$sql=$sql."m.location_id,l.location_detail,m.saleprice,m.rentprice,";
$sql=$sql."m.img1,m.img2,m.img3,m.img4,m.img5,m.landarea,m.livingarea,";
$sql=$sql."m.livingrooms,m.bedrooms,m.bathrooms,m.furnished,m.airconunits,m.name  from masterref m";
$sql=$sql." inner join category c on m.category_id=c.category_id ";
$sql=$sql." inner join poptype p on m.poptype_id=p.poptype_id ";
$sql=$sql." inner join location l on m.location_id=l.location_id ";
$sql=$sql." where m.category_id = '2' And p.poptype_id='2' ";
$sql =$sql." ORDER BY refno DESC  LIMIT$start,$limit";

สีแดงเอาออก
แล้วไปนับแถวเอา

Gaylydigg

ผมหาโค๊ดมาใหม่ครับผม ตรง $baseurl ไม่ทราบว่าต้องใส่ยังไงครับผม

อันนี้คือโค๊ดเดิม

<b>Page : &nbsp;&nbsp;
                          <?
/* ??????.???? */
$page = ceil($total/$limit); // ??? record ???.??? ??????? ?????????????.??.?????????
/* ???????? ???? ?????????? ????.??? ???? ??????????????? 3 ?????????????? 1 2 3 */
for($i=1;$i<=$page;$i++){
if($_GET['page']==$i){ //.???????? page ??. ??? ???????????
echo "[<a href='?start=".$limit*($i-1)."&page=$i' class='link'>$i</A>]"; //???.?? ???.???? ?.????????? 1
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i' class='link'>$i</A>]"; //???.?? ???.???? ?.????????? 2
}
}

?>
                        </b>

//////////////////////////////////////////////////////////////////////

   
           <?
function displayPaging( $total, $limit, $pagenumber, $baseurl ){
// how many page numbers to show in list at a time
$showpages = "10"; // 1,3,5,7,9...

// set up icons to be used
$icon_path = 'icons/';
$icon_param = 'align="middle" style="border:0px;" ';
$icon_first= '[First page]';
$icon_last= '[Lastpage]';
$icon_previous= '<< Previous';
$icon_next= 'Next >>';
///////////////////
///////////////////

// do calculations
$pages = ceil($total / $limit);
$offset = ($pagenumber * $limit) - $limit;
$end = $offset + $limit;

// prepare paging links
$html .= '<div id="pageLinks">';
// if first link is needed
if($pagenumber > 1) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.'">'.$icon_first.'</a> ';
}
// if previous link is needed
if($pagenumber > 2) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.''.$previous.'">'.$icon_previous.'</a> ';
}
// print page numbers
if ($pages>=2) { $p=1;
$html .= "| Page: ";
$pages_before = $pagenumber - 1;
$pages_after = $pages - $pagenumber;
$show_before = floor($showpages / 2);
$show_after = floor($showpages / 2);
if ($pages_before < $show_before){
$dif = $show_before - $pages_before;
$show_after = $show_after + $dif;
}
if ($pages_after < $show_after){
$dif = $show_after - $pages_after;
$show_before = $show_before + $dif;
}
$minpage = $pagenumber - ($show_before+1);
$maxpage = $pagenumber + ($show_after+1);

if ($pagenumber > ($show_before+1) && $showpages > 0) {
$html .= " ... ";
}
while ($p <= $pages) {
if ($p > $minpage && $p < $maxpage) {
if ($pagenumber == $p) {
$html .= " <b>".$p."</b>";
} else {
$html .= ' <a href="'.$baseurl.$p.'">'.$p.'</a>';
}
}
$p++;
}
if ($maxpage-1 < $pages && $showpages > 0) {
$html .= " ... ";
}
}
// if next link is needed
if($end < $total) { $next = $pagenumber +1;
if ($next != ($p-1)) {
$html .= ' | <a href="'.$baseurl.$next.'">'.$icon_next.'</a>';
} else {$html .= ' | ';}
}
// if last link is needed
if($end < $total) { $last = $p -1;
$html .= ' <a href="'.$baseurl.$last.'">'.$icon_last.'</a>';
}
$html .= '</div>';
// return paging links
return $html;
}
?>



      <?
echo displayPaging( $total, $limit, $pagenumber, $baseurl );
/*
$total = จำนวนข้อมูลทั้งหมด
$limit = จำนวนข้อมูลต่อ 1 หน้า
$pagenumber = เลขหน้าปัจจุบัน
$baseurl = 'start=".$limit*($i-1)."&page=$i'*/

?>
     

Gaylydigg

ช่วยผมหน่อยคร๊าบบบบบบบบบบบบบ นั่งทำหลายชั่วโมงแล้วยังไม่ได้เลย  :-X

Kusumoto

เห็นหน้าเรียก SQL แล้วยอมเลยครับ ไม่เคยเขียนยาวมากเท่านี้มาก่อนเลย
[direct=http://kusumotolab.com]Kusumoto Blog![/direct]
[direct=http://twitter.com/kusumoto_ton]My Twitter[/direct]
รับออกแบบและทำเว็บไซต์ ออกแบบระบบเครือข่าย

Gaylydigg

เอาใหม่ครับผม  :-X

<b>Page : &nbsp;&nbsp;
<?

$page = ceil($total/$limit);
for($i=1;$i<=$page;$i++){
if($_GET['page']==$i){
echo "[<a href='?start=".$limit*($i-1)."&page=$i' class='link'>$i</A>]";
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i' class='link'>$i</A>]";
}
}

?>

ข้างบนคือการแสดงผลแบบเก่าครับ จะขึ้นเป็น 1 2 3 4 5 ตลอดดูแล้วไม่สวยงาม
ส่วนข้างล่างเป็นการแสดงผลแบบใหม่ แต่ผมติดตรงคลิ๊ก next แล้วไม่ได้ครับผม ผมไม่รู้ว่า $baseurl ต้องใส่ยังไง
โค๊ดได้ล่างผมก๊อบมาจาก http://www.i-keng.com/2009/09/26/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%9A%E0%B9%88%E0%B8%87%E0%B8%AB%E0%B8%99%E0%B9%89%E0%B8%B2%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-php-php-paging/

รบกวนท่านผู้รู้ด้วยครับ


<?
function displayPaging( $total, $limit, $pagenumber, $baseurl ){
// how many page numbers to show in list at a time
$showpages = "10"; // 1,3,5,7,9...

// set up icons to be used
$icon_path = 'icons/';
$icon_param = 'align="middle" style="border:0px;" ';
$icon_first= '[First page]';
$icon_last= '[Lastpage]';
$icon_previous= '<< Previous';
$icon_next= 'Next >>';
///////////////////
///////////////////

// do calculations
$pages = ceil($total / $limit);
$offset = ($pagenumber * $limit) - $limit;
$end = $offset + $limit;

// prepare paging links
$html .= '<div id="pageLinks">';
// if first link is needed
if($pagenumber > 1) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.'">'.$icon_first.'</a> ';
}
// if previous link is needed
if($pagenumber > 2) { $previous = $pagenumber -1;
$html .= '<a href="'.$baseurl.''.$previous.'">'.$icon_previous.'</a> ';
}
// print page numbers
if ($pages>=2) { $p=1;
$html .= "| Page: ";
$pages_before = $pagenumber - 1;
$pages_after = $pages - $pagenumber;
$show_before = floor($showpages / 2);
$show_after = floor($showpages / 2);
if ($pages_before < $show_before){
$dif = $show_before - $pages_before;
$show_after = $show_after + $dif;
}
if ($pages_after < $show_after){
$dif = $show_after - $pages_after;
$show_before = $show_before + $dif;
}
$minpage = $pagenumber - ($show_before+1);
$maxpage = $pagenumber + ($show_after+1);

if ($pagenumber > ($show_before+1) && $showpages > 0) {
$html .= " ... ";
}
while ($p <= $pages) {
if ($p > $minpage && $p < $maxpage) {
if ($pagenumber == $p) {
$html .= " <b>".$p."</b>";
} else {
$html .= ' <a href="'.$baseurl.$p.'">'.$p.'</a>';
}
}
$p++;
}
if ($maxpage-1 < $pages && $showpages > 0) {
$html .= " ... ";
}
}
// if next link is needed
if($end < $total) { $next = $pagenumber +1;
if ($next != ($p-1)) {
$html .= ' | <a href="'.$baseurl.$next.'">'.$icon_next.'</a>';
} else {$html .= ' | ';}
}
// if last link is needed
if($end < $total) { $last = $p -1;
$html .= ' <a href="'.$baseurl.$last.'">'.$icon_last.'</a>';
}
$html .= '</div>';
// return paging links
return $html;
}
?>



<?
echo displayPaging( $total, $limit, $pagenumber, $baseurl );
/*
$total = จำนวนข้อมูลทั้งหมด
$limit = จำนวนข้อมูลต่อ 1 หน้า
$pagenumber = เลขหน้าปัจจุบัน
$baseurl = 'start=".$limit*($i-1)."&page=$i'*/

?>

Kusumoto

ตัวแปร เยอะจนผมงงเลย หรือว่าเราไม่เข้าใจเอง  :wanwan031: :wanwan031:
[direct=http://kusumotolab.com]Kusumoto Blog![/direct]
[direct=http://twitter.com/kusumoto_ton]My Twitter[/direct]
รับออกแบบและทำเว็บไซต์ ออกแบบระบบเครือข่าย