เกี่ยวกับการsearch จาก listmenuแล้วเอามาแบ่งหน้า
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา เกี่ยวกับการsearch จาก listmenuแล้วเอามาแบ่งหน้า
เกี่ยวกับการsearch จาก listmenuแล้วเอามาแบ่งหน้า ผมลองแก้ไขมาหมดทุกแบบแล้วก็ยังทำไม่ได้ใครพอจะเคยทำแนวนี้มาช่วยแนะนำด้วย นะครับ
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 234 235 236 237 238 239 240 241 242 243 244 245 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type= "text/css" > .browse_page{ clear:both; margin-left:12px; height:35px; margin-top:5px; display:block; } .browse_page a,.browse_page a:hover{ display:block; height:18px; width:18px; font-size:10px; float:left; margin-right:2px; border:1px solid #CCCCCC; background-color:#F4F4F4; color:#333333; text-align:center; line-height:18px; font-weight:bold; text-decoration:none; } .browse_page a:hover{ border:1px solid #0A85CB; background-color:#0A85CB; color:#FFFFFF; } .browse_page a.selectPage{ display:block; height:18px; width:18px; font-size:10px; float:left; margin-right:2px; border:1px solid #0A85CB; background-color:#0A85CB; color:#FFFFFF; text-align:center; line-height:18px; font-weight:bold; } .browse_page a.SpaceC{ display:block; height:18px; width:18px; font-size:10px; float:left; margin-right:2px; border:0px dotted #0A85CB; font-size:11px; background-color:#FFFFFF; color:#333333; text-align:center; line-height:18px; font-weight:bold; } .browse_page a.naviPN{ width:50px; font-size:12px; display:block; height:18px; float:left; border:1px solid #0A85CB; background-color:#0A85CB; color:#FFFFFF; text-align:center; line-height:18px; font-weight:bold; } .browse_page a.naviPN:hover{ width:50px; font-size:12px; display:block; height:18px; float:left; border:1px solid #0A85CB; background-color:#0A85CB; color:#FFFFFF; text-align:center; line-height:18px; font-weight:bold; } </style> </head> <body> <p> <?php $link =mysql_connect( "localhost" , "root" , "gnothnapha" ); mysql_select_db( "dataedl" ); ?> </p> <form name= "search" method= "post" action= "page1.php" > <span class = "style35" >search</span> <input name= "keyword" type= "text" class = "Lao" value= "<? echo" $keyword "; ?>" /> from <select name= "fields" class = "Lao" > <option value= "<? echo " $fields "; ?>" ><? echo "$fields" ; ?></option> <option value= "sub_name" >sub</option> <option value= "st_no" >id</option> <option value= "install" >place</option> <option value= "tf_name" >name</option> <option value= "ratedpower" >power</option> </select> <input name= "Submit" type= "submit" class = "Lao" value= "search" > </FORM> <?php // ?????????????? ????????????????????? function page_navigator( $before_p , $plus_p , $total , $total_p , $chk_page ){ global $urlquery_str ; $pPrev = $chk_page -1; $pPrev =( $pPrev >=0)? $pPrev :0; $pNext = $chk_page +1; $pNext =( $pNext >= $total_p )? $total_p -1: $pNext ; $lt_page = $total_p -4; if ( $chk_page >0){ echo "<a href='?keyword=$keyword&fields=$fields&s_page=$pPrev&urlquery_str=" . $urlquery_str . "' class='naviPN'>Prev</a>" ; } if ( $total_p >=11){ if ( $chk_page >=4){ echo "<a $nClass href='?keyword=$keyword&fields=$fields&s_page=0&urlquery_str=" . $urlquery_str . "'>1</a><a class='SpaceC'>. . .</a>" ; } if ( $chk_page <4){ for ( $i =0; $i < $total_p ; $i ++){ $nClass =( $chk_page == $i )? "class='selectPage'" : "" ; if ( $i <=4){ echo "<a $nClass href='?keyword=$keyword&fields=$fields&s_page=$i&urlquery_str=" . $urlquery_str . "'>" . intval ( $i +1). "</a> " ; } if ( $i == $total_p -1 ){ echo "<a class='SpaceC'>. . .</a><a $nClass href='?keyword=$keyword&fields=$fields&s_page=$i&urlquery_str=" . $urlquery_str . "'>" . intval ( $i +1). "</a> " ; } } } if ( $chk_page >=4 && $chk_page < $lt_page ){ $st_page = $chk_page -3; for ( $i =1; $i <=5; $i ++){ $nClass =( $chk_page ==( $st_page + $i ))? "class='selectPage'" : "" ; echo "<a $nClass href='?keyword=$keyword&fields=$fields&s_page=" . intval ( $st_page + $i ). "'>" . intval ( $st_page + $i +1). "</a> " ; } for ( $i =0; $i < $total_p ; $i ++){ if ( $i == $total_p -1 ){ $nClass =( $chk_page == $i )? "class='selectPage'" : "" ; echo "<a class='SpaceC'>. . .</a><a $nClass href='?keyword=$keyword&fields=$fields&s_page=$i&urlquery_str=" . $urlquery_str . "'>" . intval ( $i +1). "</a> " ; } } } if ( $chk_page >= $lt_page ){ for ( $i =0; $i <=4; $i ++){ $nClass =( $chk_page ==( $lt_page + $i -1))? "class='selectPage'" : "" ; echo "<a $nClass href='?keyword=$keyword&fields=$fields&s_page=" . intval ( $lt_page + $i -1). "'>" . intval ( $lt_page + $i ). "</a> " ; } } } else { for ( $i =0; $i < $total_p ; $i ++){ $nClass =( $chk_page == $i )? "class='selectPage'" : "" ; echo "<a href='?keyword=$keyword&fields=$fields&s_page=$i&urlquery_str=" . $urlquery_str . "' $nClass ' >" . intval ( $i +1). "</a> " ; } } if ( $chk_page < $total_p -1){ echo "<a href='?keyword=$keyword&fields=$fields&s_page=$pNext&$keyword&fields=$fields&urlquery_str=" . $urlquery_str . "' class='naviPN'>Next</a>" ; } } //echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> "; new1111111 ?> <ul> <?php //include ("../connecttion.inc.php"); if ( empty ( $keyword ) or empty ( $fields )) { $q .= "select * from tredl order by st_no asc " ; } else { $q = "select * from tredl where $fields like '%$keyword%'" ; } //$q="select * from tredl where 1"; //$q.=" ORDER BY st_no "; $qr =mysql_query( $q ); $total =mysql_num_rows( $qr ); $e_page =10; // ????? ????????????????????????????? if (!isset( $_GET [ 's_page' ])){ $_GET [ 's_page' ]=0; } else { $chk_page = $_GET [ 's_page' ]; $_GET [ 's_page' ]= $_GET [ 's_page' ]* $e_page ; } //q="select * from tredl where $fields like '%$keyword%'"; $q = "SELECT * FROM tredl order by st_no asc" ; $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 ); ?> <table width= "500" border= "0" cellspacing= "0" cellpadding= "0" > <tr> <td width= "35" height= "20" align= "center" bgcolor= "#CCCCCC" >#</td> <td height= "20" align= "center" bgcolor= "#CCCCCC" >name</td> <td width= "150" height= "20" align= "center" bgcolor= "#CCCCCC" >type</td> <td height= "20" colspan= "2" align= "center" bgcolor= "#CCCCCC" >edite</td> </tr> <?php $i =1; while ( $rs =mysql_fetch_array( $qr )){ ?> <tr> <td height= "20" align= "center" ><?=( $chk_page * $e_page )+ $i ?></td> <td height= "20" align= "left" > <?= $rs [ 'st_no' ]?></td> <td height= "20" align= "center" > <?= $rs [ 'ratedpower' ]?></td> <td width= "45" height= "20" align= "center" ><a href= "#<?=$rs['st_no']?>" class = "updateItem" >edite</a></td> <td width= "45" height= "20" align= "center" ><a href= "#<?=$rs['st_no']?>" class = "delItem" > delete </a></td> </tr> <?php $i ++; } ?> </table> </ul> <?php if ( $total >0){ ?> <div class = "browse_page" > <?php // ???????????????????? ????????????????????? page_navigator( $before_p , $plus_p , $total , $total_p , $chk_page ); ?> <? echo "$total" ;?> </div> <?php } ?> </body> </html> |
ผมลองแก้ไขมาหมดทุกแบบแล้วก็ยังทำไม่ได้ใครพอจะเคยทำแนวนี้มาช่วยแนะนำด้วยนะครับ
ขอบคุณล่วงหน้าคับ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เปลี่ยนรูปแบบการส่งข้อมูล การค้นหา จาก post เป็น get
1 | <form name= "search" method= "get" action= "page1.php" > |
เพิ่มส่วนของการแบ่งหน้า เป็น
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php if ( $total >0){ ?> <div class = "browse_page" > <?php $urlquery_str = "" ; if (isset( $_GET [ 'keyword' ]) && $_GET [ 'keyword' ]!= "" ){ $urlquery_str .= "&keyword=" . $_GET [ 'keyword' ]; } if (isset( $_GET [ 'fields' ]) && $_GET [ 'fields' ]!= "" ){ $urlquery_str .= "&fields=" . $_GET [ 'fields' ]; } page_navigator( $before_p , $plus_p , $total , $total_p , $chk_page ); ?> </div> <?php } ?> |

เก่งจัง, ทำได้แล้ว
ขอบคุณมากคับ

ผมเอาไปใช้ยังไม่ได้ ครับ
ค่าส่งแต่ถ้าคลิกก็กลับหน้าแรก
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 | <div id= "content" > <? include "../common/menu.php" ?> <div id= "ContentData" > <div id= "ContentData1" > <div id= "ContentData2" > <!-- contentDATA --> <fieldset > <p> <form name "add" method= "get" action= "" > <h3> โครงการสาขา <select name= "id_major" > <? for ( $im =1; $im <=7;++ $im ){ echo "<option value={$im} " ; if ( $_GET [ 'id_major' ]== $im ){ echo "selected='selected'" ; } echo ">" . $MAJOR [ $im ]. "</option>" ; }?> </select> ประจำปี พ.ศ. <select name= "budge_year" > <? for ( $i = $nowYear ; $i >= $beginYear ;-- $i ){ $j = $i +543 ; echo "<option value=$i " ; if ( $_GET [ 'budge_year' ]== $i ){ echo "selected='selected'" ; } echo ">" . $j . "</option>" ; } ?> </select> <input name= "on" type= "hidden" id= "on" value= "1" /> <input name= "button" type= "submit" class = "button" value= "ค้นหา" /> </form> </h3> <form action= "add.php" > <div id= "submitadd" > <input type= "submit" class = "button" value= "เพิ่มข้อมูลโครงการใหม่" /> </div> </form> <?php if ( $_GET [ 'on' ]==1) { $q = "SELECT * FROM project where id_major=$_GET[id_major] AND budge_year=$_GET[budge_year] " ; } else { $q = "SELECT * FROM project WHERE id_major=1 AND `budge_year` = '$nowYear'" ; } //$q="select * from tredl where 1"; //$q.=" ORDER BY st_no "; $qr =mysql_query( $q ); $total =mysql_num_rows( $qr ); $e_page =5; // ????? ????????????????????????????? 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 ); echo $q ; ?> <table width= "500" border= "1" cellspacing= "0" cellpadding= "0" > <tr> <th>ลำดับ</th> <th>ชื่อโครงการ</th> <th>สถานะโครงการ</th> <th>งบประมาณ</th> <th>ลบ</th> <th>แก้ไข</th> </tr> <?php $i =1; while ( $rs =mysql_fetch_array( $qr )){ ?> <tr> <td align= "center" ><?=( $chk_page * $e_page )+ $i ?></td> <td><?= $rs [ 'project_name' ];?></td> <td><?= $rs [ 'project_status' ];?></td> <td><?= $rs [ 'budget' ];?></td> <td><a href= "JavaScript:if(confirm('ต้องการลบข้อมูลโครงการนี้')==true){window.location='showdata.php?action=del&&id_project=<?=$objResult['id_project']?>';}" >ลบ</a></td> <td><a href= "edit.php?id_project=<?=$objResult['id_project']?>" >แก้ไข</a></td> </tr> <?php $i ++; } ?> </table> <?php if ( $total >0){ ?> <div class = "browse_page" > <?php $urlquery_str = "" ; ตรงนี้เปลี่ยนแล้ว if (isset( $_GET [ 'id_major' ]) && $_GET [ 'id_major' ]!= "" ){ $urlquery_str .= "&id_major=" . $_GET [ 'id_major' ]; } if (isset( $_GET [ 'budge_year' ]) && $_GET [ 'budge_year' ]!= "" ){ $urlquery_str .= "&budge_year=" . $_GET [ 'budge_year' ]; } page_navigator( $before_p , $plus_p , $total , $total_p , $chk_page ); ?> </div> <?php } ?> </fieldset> <!-- contentDATA --> </div> </div> </div> <div class = "clear" ></div> </div> <!-- content --> |

ได้แล้วแล้วครับ โค้ดนี้ คงเก็บแล้วใช้อีกนาน อิอิ กว่าจะโค้ดแบ่งที่สมบูณร์ ที่นี้เจ๋งสุดครับ

ขอโค้ดได้ไหมครับ....................
พอดีตอน Search เข้ามาแบ่งหน้าได้ครับ...............
ต่อพอกดไป 4-5 ครั้ง มันหลุดครับ กลายเป็นว่าง.............
ตอน Search ค่าเป็นงี้ครับ http://localhost/test3/receive_sss/searchOK.php?s_page=3&urlquery_str=&keywords=วิศว
พอกดไป 4- 5 ปุ่มหายไปทั้งหน้าพร้อมลิงค์นี้ครับ http://localhost/test3/receive_sss/searchOK.php?s_page=3
อยากทราบว่าโค้ดส่วนนี้หายไปไหนครับ......&urlquery_str=&keywords=วิศว
ยังไงก็ขอบคุณครับ..........ส่งเมลล์มาตามนี้นะครับ.......................ru_2019@hotmail.com
