ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

offing
PHP VIP Members
PHP VIP Members
โพสต์: 1527
ลงทะเบียนเมื่อ: 18/08/2014 10:01 am

ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โพสต์ที่ยังไม่ได้อ่าน โดย offing »

ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โค้ด: เลือกทั้งหมด

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup(test_insert_sql);

$template->set_filenames(array(
'body' => 'test_insert_sql_history.html'

)); 
$search = request_var('search',''); //รับค่าจากดอปดาวในhtml รูปแบบ(20000-30000)
$s1 = explode('-',$search); //แบ่งข้อความ
$a = $s1[0]; //20000เกบในa
$b = $s1[1];//30000เกบในb
$min   = request_var('min', $a);//ถ้ามีการกดหน้า2 จะรับค่าminเกบในmin
$max   = request_var('max', $b);
$start   = request_var('start', 0); //เริ่มจากลำดับ
$limit   = request_var('limit', (int)5 );// จำนวนที่จะให้เเสดง

if($search == '100000+'){
   
    $data = 'SELECT * FROM ' . OFFING_TABLE . ' WHERE sa_total > 100000 order by search_id ASC';
     $row = "SELECT COUNT(*) AS sumrow FROM ". OFFING_TABLE.' WHERE sa_total > 100000 order by search_id ASC';
}

//เกือบทุกเงื่อนไขจะเข้าตัวนี้
else{

$data = 'SELECT * FROM '.OFFING_TABLE.' where sa_total between "'.$min.'" and  "'.$max.'" order by search_id ASC'; 

$row = "SELECT COUNT(*) AS sumrow FROM ". OFFING_TABLE.' where sa_total between "'.$min.'" and "'.$max.'" order by search_id ASC'; 
}
$result = $db->sql_query($row);

$total_data = (int) $db->sql_fetchfield('sumrow');
$result = $db->sql_query_limit($data, $limit, $start);


while($show = $db->sql_fetchrow($result)){
   $template->assign_block_vars('somerow', array(
      'VAR1' => "$show[name]",
      'VAR2' => "$show[sa_m]",
       'VAR3' => "$show[sa_f]",
       'VAR4' => "$show[age_m]",
       'VAR5' => "$show[age_f]",
       'VAR6' => "$show[status_l]",
       'VAR7' => "$show[status_c]",
       'VAR8' => "$show[status_ma]",
       'VAR9' => "$show[status_f]",
       'VAR10' => "$show[status_ceo]",
       'VAR11' => "$show[time]",
       'VAR12' => "$show[money]",
       'VAR13' => "$show[ip]",
   ));
}

$pagination_url = append_sid($phpbb_root_path . 'test_insert_sql_history.' . $phpEx."?min=".$min."&max=".$max,'');

$template->assign_vars(array(
      'PAGINATION'        => generate_pagination($pagination_url, $total_data, $limit, $start),
      'PAGE_NUMBER'       => on_page($total_use, $limit, $start), 
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_header($l_title, false);
page_footer();


?>

มีข้อมูลในฐานข้อมูล10record
หน้าค้นหา
1.jpg
1.jpg (10.19 KiB) Viewed 612 times
หน้าแรก
2.jpg
2.jpg (50.99 KiB) Viewed 612 times
หน้า2
3.jpg
3.jpg (16.46 KiB) Viewed 612 times
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41336
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ตัวอย่าง sql_query_limit

โค้ด: เลือกทั้งหมด

$post_id = 25;

// Start on row 10
$start = 10;

// Select 5 rows (limit/offset)
$limit = 5

$sql = 'SELECT *
    FROM ' . POSTS_TABLE . ' 
    WHERE post_id = ' . (int) $post_id;
$result = $db->sql_query_limit($sql, $limit, $start);
 
ถ้าส่งตัวแปลตามเงื่อนไข มา เพิ่มเข้าไปที่ คำสั่ง sql WHERE
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

Re: ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

น่าจะเขียนคบแล้วนะคับ ในwhere

แล้ว $result = $db->sql_query_limit($sql, $limit, $start); เขียนตามนี้เลยคับ

พลาดจุดไหนไปคับ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41336
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ส่งตัวแปล ไปตาม url ของหน้าใหม่ หรือยัง
search, max, min
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
offing
PHP VIP Members
PHP VIP Members
โพสต์: 1527
ลงทะเบียนเมื่อ: 18/08/2014 10:01 am

Re: ติดปัญหาการแบ่งหน้าพอกดหน้า2ข้อมูลไม่ขึ้น

โพสต์ที่ยังไม่ได้อ่าน โดย offing »

เรียบร้อยแล้วคับ


ตอนรับค่าตัวแปรในหน้าแรกรับค่าsearchมาเพียงตัวเดียวส่วนค่า
min,max เรามาทำการexplode เพื่อใช้นำไปwhere หาช่วงข้อมูลที่ต้องการ

โค้ด: เลือกทั้งหมด

$search = request_var('search','');
$s1 = explode('-',$search);
$a = $s1[0];
$b = $s1[1];
$min   = request_var('min', $a);
$max   = request_var('max', $b);
$start   = request_var('start', 0); /
$limit   = request_var('limit', (int)5);

ส่วนขั้นตอนการ append_sid กลับมาเพื่อดูหน้า 2,3,4,.......
เราไม่ต้องส่งค่าmaxกลับไป เพียงส่ง

โค้ด: เลือกทั้งหมด

$pagination_url = append_sid($phpbb_root_path . 'test_insert_sql_history.' . $phpEx."?search=".$search,'');
\

ก็เป็นอันเสร็จ
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 59