egturnkey Posted October 19, 2010 Share Posted October 19, 2010 Hello friends, if i've database table (mytable) has the following ids 1 2 3 4 5 6 and i want to get it with limit the first (1 to 3 ) only $sql ="select * from mytable LIMIT 3"; this will show the first 3 (1,2,3) how then i write code that shows which is after 3 so it shows me 4 5 6 and if there any way i can say $sql ="select * from mytable LIMIT (first half of ids)"; and (shows 1,2,3..ect till half) $sql ="select * from mytable LIMIT (second half of ids)"; will (shows 4,5,6...ect till end) thank you Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted October 19, 2010 Share Posted October 19, 2010 Try an ORDER BY desc (then add the LIMIT again). Quote Link to comment Share on other sites More sharing options...
egturnkey Posted October 19, 2010 Author Share Posted October 19, 2010 LOL i've an idea .. i may use (Count) to get the total count of ids -->1 then i divied it by 2 to be $half = $count / 2 then i use $half to be $sql ="select * from mytable LIMIT 0,$half"; and to get the seond half lol $sql ="select * from mytable LIMIT $half,$count"; lol looks very hurting way is it possible Ops, what if we have odd number of ids Quote Link to comment Share on other sites More sharing options...
egturnkey Posted October 19, 2010 Author Share Posted October 19, 2010 Try an ORDER BY desc (then add the LIMIT again). thank you for your answer but i mean if i've database table with alot of ids ( but i don't know how many ) and willing to cut it into 2 parts part 1 = show from 1 to exact half of the ids part 2 = show from exact half of the ids to the end Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted October 19, 2010 Share Posted October 19, 2010 Ahh. Then yes your suggestion of total divided by two. You may want to incorporate the modulus for the cases where it's an odd total: http://php.net/manual/en/internals2.opcodes.mod.php Quote Link to comment Share on other sites More sharing options...
egturnkey Posted October 19, 2010 Author Share Posted October 19, 2010 Ahh. Then yes your suggestion of total divided by two. You may want to incorporate the modulus for the cases where it's an odd total: http://php.net/manual/en/internals2.opcodes.mod.php thanks for help , that make it more complex lol now with your help i can know if it even number or odd number so i can use double way if even then will divided by 2 if not even ( sure will be odd ) then i will divided by 2 then sub - 1 lol life is so hard so let the total ids $count if ($count % 2) { $half = $count / 2 // not eved so divied by 2 } else { $makeiteven = $count - 1 // odd number so - 1 $half = $makeiteven / 2 // divied by 2 then } then part 1 $sql ="select * from mytable LIMIT 0,$half"; and part 2 $sql ="select * from mytable LIMIT $half,$count"; i wonder is there any way makes life more easy than that way Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.