สอบถามเรื่อง แบ่งหน้าหน่อยคะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามเรื่อง แบ่งหน้าหน่อยคะ
สอบถามเรื่อง แบ่งหน้าหน่อยคะ
เนื่องจากได้ทดลองทำแบ่งหน้าจาก
https://www.ninenik.com/แบ่งหน้า_ด้วย_php_เพิ่ม_หัว_ท้าย_ด้วย_thead_และ_tfoot_อย่างง่าย-468.html
แล้ว error ที่ตัว chk_page ไม่ทราบว่าต้องแก้ยังไงหรอคะ
รบกวนด้วยนะคะ
https://www.ninenik.com/แบ่งหน้า_ด้วย_php_เพิ่ม_หัว_ท้าย_ด้วย_thead_และ_tfoot_อย่างง่าย-468.html
แล้ว error ที่ตัว chk_page ไม่ทราบว่าต้องแก้ยังไงหรอคะ
รบกวนด้วยนะคะ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
11
อย่างนี้นี่เอง 555 โง่อยู่ตั้งนาน แหะๆ 
ขอบคุณมากๆนะคะ

ขอบคุณมากๆนะคะ


ความคิดเห็นที่
12
ขอถามอีกเรื่องนึงนะคะ
ต้องการให้หมวดที่ไม่มีข้อมูล แสดงข้อความว่า ไม่มีข้อมูล อ่าคะ
ไม่ทราบว่าต้องใส่โค้ดยังงัยหรอคะ
ลองใช้ if ครอบตารางแสดงข้อมูลแล้ว ก็ไม่ได้อ่าคะ
รบกวนด้วยนะคะ
ต้องการให้หมวดที่ไม่มีข้อมูล แสดงข้อความว่า ไม่มีข้อมูล อ่าคะ
ไม่ทราบว่าต้องใส่โค้ดยังงัยหรอคะ
ลองใช้ if ครอบตารางแสดงข้อมูลแล้ว ก็ไม่ได้อ่าคะ
รบกวนด้วยนะคะ


ความคิดเห็นที่
13

ดูการวางนี้เป็นแนวทาง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | <?php // เชื่อมต่อกับฐานข้อมูล require_once ( "dbconnect.php" ); include_once ( "func_page_navi.php" ); // เรียกใช้งานฟังก์ชั่นแบ่งหน้า $_GET [ 'myradio' ]=(isset( $_GET [ 'myradio' ]))? $_GET [ 'myradio' ]:NULL; $_GET [ 'myselect' ]=(isset( $_GET [ 'myselect' ]))? $_GET [ 'myradio' ]:NULL; $_GET [ 'mycheckbox' ]=(isset( $_GET [ 'mycheckbox' ]))? $_GET [ 'myradio' ]:NULL; $_GET [ 'mycheckbox2' ]=(isset( $_GET [ 'mycheckbox2' ]))? $_GET [ 'myradio' ]:NULL; $chk_page =(isset( $chk_page ))? $chk_page :NULL; ?> <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Form complex search</title> <link rel= "stylesheet" href= "page_navi.css" > </head> <body> <div style= "margin:auto:width:80%;" > <br><br> <div style= "margin:auto;text-align:left;width:700px;" > <!--ส่วนสร้างฟอร์ม สำหรับค้นหา --> <form id= "form_search" name= "form_search" method= "get" action= "" > เลือกอย่างหนึ่งอย่างใด หรือไม่เลือกก็ได้ || <input type= "radio" name= "myradio" id= "myradio1" value= "จ" <?=( $_GET [ 'myradio' ]== "จ" )? " checked" : "" ?>> มี "จ" <input type= "radio" name= "myradio" id= "myradio2" value= "ม" <?=( $_GET [ 'myradio' ]== "ม" )? " checked" : "" ?>> มี "ม" <input type= "radio" name= "myradio" id= "myradio3" value= "ส" <?=( $_GET [ 'myradio' ]== "ส" )? " checked" : "" ?>> มี "ส" <br><br> เลือกอย่างหนึ่งอย่างใด หรือไม่เลือกก็ได้ || <select name= "myselect" id= "myselect" > <option value= "" >เลื่อกเงื่่อนไข</option> <option value= "ก" <?=( $_GET [ 'myselect' ]== "ก" )? " selected" : "" ?> >ขึ้นต้นด้วย ก</option> <option value= "อุ" <?=( $_GET [ 'myselect' ]== "อุ" )? " selected" : "" ?>>ขึ้นต้นด้วย อุ</option> </select> <br><br> พิมพ์บางคำ บางตัว หรือไม่พิมพ์ก็ได้ || <input type= "text" name= "keyword" id= "keyword" value= "<?=$_GET['keyword']?>" /> <br><br> เลือกอย่างหนึ่งอย่างใด หรือเลือกทั้งสอง หรือไม่เลือกก็ได้ || <input type= "checkbox" name= "mycheckbox" id= "mycheckbox" value= "นี" <?=( $_GET [ 'mycheckbox' ]== "นี" )? " checked" : "" ?> > ลงท้ายด้วย "นี" <input type= "checkbox" name= "mycheckbox2" id= "mycheckbox2" value= "คร" <?=( $_GET [ 'mycheckbox2' ]== "คร" )? " checked" : "" ?>> ลงท้ายด้วย "คร" <br><br> <input type= "submit" name= "button" id= "button" value= "ค้นหา" /> <input type= "button" name= "btn_reset" value= "Reset" onclick= "window.location='form_complex_search.php'" > </form> <br /> <table width= "100%" border= "0" align= "center" cellpadding= "0" cellspacing= "00" > <?php $i =1; $sql = "SELECT * FROM tbl_provinces WHERE 1 " ; // เงื่อนไขสำหรับ radio if (isset( $_GET [ 'myradio' ]) && $_GET [ 'myradio' ]!= "" ){ // ต่อคำสั่ง sql $sql .= " AND province_name LIKE '%" .trim( $_GET ['myradio '])."%' "; } // เงื่อนไขสำหรับ input text if (isset( $_GET [ 'keyword' ]) && $_GET [ 'keyword' ]!= "" ){ // ต่อคำสั่ง sql $sql .= " AND province_name LIKE '%" .trim( $_GET ['keyword '])."%' "; } // เงื่อนไขสำหรับ select if (isset( $_GET [ 'myselect' ]) && $_GET [ 'myselect' ]!= "" ){ // ต่อคำสั่ง sql $sql .= " AND province_name LIKE '" .trim( $_GET ['myselect '])."%' "; } // เงื่อนไขสำหรับ checkbox if ((isset( $_GET [ 'mycheckbox' ]) && $_GET [ 'mycheckbox' ]!= "" ) || (isset( $_GET [ 'mycheckbox2' ]) && $_GET [ 'mycheckbox2' ]!= "" )){ // ต่อคำสั่ง sql if ( $_GET [ 'mycheckbox' ]!= "" && $_GET [ 'mycheckbox2' ]!= "" ){ $sql .= " AND (province_name LIKE '%" .trim( $_GET ['mycheckbox '])."' OR province_name LIKE '%".trim($_GET[' mycheckbox2 '])."' )"; } elseif ( $_GET [ 'mycheckbox' ]!= "" ){ $sql .= " AND province_name LIKE '%" .trim( $_GET ['mycheckbox '])."' "; } elseif ( $_GET [ 'mycheckbox2' ]!= "" ){ $sql .= " AND province_name LIKE '%" .trim( $_GET ['mycheckbox2 '])."' "; } else { } } // echo $sql; $result = $mysqli ->query( $sql ); $total = $result ->num_rows; $e_page =10; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า if (!isset( $_GET [ 'pages' ])){ $_GET [ 'pages' ]=0; } else { $_GET [ 'pages' ]= $_GET [ 'pages' ]-1; if ( $_GET [ 'pages' ]<0){ $_GET [ 'pages' ]=0; } $chk_page = $_GET [ 'pages' ]; $_GET [ 'pages' ]= $_GET [ 'pages' ]* $e_page ; } $sql .= " ORDER BY province_id DESC LIMIT " . $_GET [ 'pages' ]. ",$e_page" ; $result = $mysqli ->query( $sql ); if ( $result && $result ->num_rows>=1){ $plus_p =( $chk_page * $e_page )+ $result ->num_rows; } else { $plus_p =( $chk_page * $e_page ); } $total_p = ceil ( $total / $e_page ); $before_p =( $chk_page * $e_page )+1; /// END PAGE NAVI ZONE ?> <?php if ( $total >0){ // Have data ?> <tbody> <tr> <td align= "left" > <br /> <table width= "100%" border= "1" cellspacing= "0" cellpadding= "2" style= "border-collapse:collapse;" > <tr> <td width= "50" height= "20" align= "center" bgcolor= "#F2F2F2" >#</td> <td height= "20" bgcolor= "#F2F2F2" > Topic</td> </tr> <?php while ( $row = $result ->fetch_array()){ ?> <tr> <td width= "60" height= "20" align= "center" ><?=(( $e_page * $chk_page )+ $i )?></td> <td height= "20" > <?= $row [ 'province_name' ]?></td> </tr> <?php $i ++; } ?> </table> <br /> </td> </tr> </tbody> <?php } else { ?> <tbody> <tr> <td align= "left" > ไม่มีข้อมูล </td> </tr> </tbody> <? } ?> <thead> <tr> <td align= "left" > <div style= "margin:auto;width:100%;" > <?php if ( $total >0){ ?> <div class = "browse_page" > <?php if ( count ( $_GET )<=1){ $urlquery_str = "?" ; } else { $para_get = "" ; foreach ( $_GET as $key => $value ){ if ( $key != "pages" ){ $para_get .= $key . "=" . $value . "&" ; } } $urlquery_str = "?$para_get" ; } // เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า page_navi( $before_p , $plus_p , $total , $total_p , $chk_page ); ?> </div> <?php } ?> </div> </td> </tr> <tr> <td height= "30" align= "left" > </td> </tr> </thead> <tfoot> <tr> <td height= "30" > </td> </tr> <tr> <td align= "left" > <div style= "margin:auto;width:100%;" > <?php if ( $total >0){ ?> <div class = "browse_page" > <?php // เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า page_navi( $before_p , $plus_p , $total , $total_p , $chk_page ); ?> </div> <?php } ?> </div> </td> </tr> </tfoot> </table> </div> </div> </body> </html> |

ความคิดเห็นที่
14
มันขึ้น Undefined variable: rs อ่าคะ

ขอบคุณทุกการสนับสนุน
![]()