Search the Community
Showing results for tags 'limit'.
-
i am creating a responsive website. I'll give you an example. I am retriving 100 items from mysql database using php. I am only showing 20 items per page using simple pagination with arrows. I keep this format on desktop and tablets. However, I would like to show less items when I am viewing the page on a smartphone. So instead of 20 items per page, it'll show 5 items per page along with the pagination arrows. I was wondering if this is possible with PHP or would I have to use javascript?
-
Hi All, I'm looking to update a mysql column weekly, where by 5 randomly selected rows are given a new random number, from between 1 and the num_rows / 5. This cycle is looped again until all the entries have a new random group for the week. It is to help mix up the players for teams for 5 aside. It needs to be able to accomodate the posibillity of the num_rows not dividing exactly by 5, using ceil perhaps? As an example Name Group a 1 b 2 c 1 d 1 e 1 f 3 g 2 h 1 i 2 j 2 k 2 Then Next week Name Group a 2 b 1 c 2 d 2 e 1 f 2 g 3 h 1 i 2 j 1 k 1 I hope that makes sense. It'll be automated via cron job. I've been really struggling with it, this is as far as I have got. $totalgroupsraw = $num_rows /5; $totalgroups = ceil ($totalgroupsraw); $i = 1; while ($i<$totalgroups) { $pie = mysql_query("UPDATE table SET columnname=5 order by rand() LIMIT 5"); $i++; }; But as you will no doubt be able to see, this doesn't work well at all. I think I am close, but I just can't seem to sort out a good way to do it. Any help much appreciated. Thanks, Matt
-
Hey guys, I'm trying to limit my query to 5 results, but TOP is not working and LIMIT obviously does not work (I usually work with MySQL). Here is my query: $query = "SELECT PERSON.PERSON_ID, PERSON.LAST_NAME, PERSON.FIRST_NAME FROM PERSON where PERSON.LAST_NAME like '%$q%' or PERSON.FIRST_NAME like '%$q%' order by PERSON.LAST_NAME"; Can someone please point me in the right direction for limiting the query to 5 results? Thank you! ~ Sarah
-
I have my website paginating files that are shown onscreen. How can I make it so the page only loads the first page's files and then when going on to the next page, it loads the files on that page? Basically what I am trying to do is reduce load time by not loading the files on the pages after page one until the user actually goes to a page after page one. index.php <?php $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1; $items_per_page = 10; $offset = ($current_page - 1) * $items_per_page; $items = glob("entries/*.php"); $total_items = count($items); $total_pages = ceil($total_items / $items_per_page); foreach (array_slice($items, $offset, $items_per_page) as $entry) { include $entry; } echo "<table summary=\"\" cellpadding=\"10\" cellspacing=\"0\" border=\"0\" class=\"global-links-menu\"><tr>"; if($current_page != 1) { $back_page = $current_page - 1; echo "<td ><p><a href='?page=$back_page'>Back</a></p></td>"; } else { $back_page = $current_page - 1; echo "<td ><p></p></td>"; } for($j=1;$j<=$total_pages;$j++) { if($j==$current_page) { echo "<td ><p>$current_page</p></td>"; } else { echo "<td ><p><a href='?page=$j' title='Page $j'>$j</a></p></td>"; } } if($current_page <= $total_pages - 1){ $next_page=$current_page+1; echo "<td ><p><a href='?page=$next_page'>Next Page</a></p></td>"; } else { echo "<td ><p></p></td>"; } /* foreach (glob("entries/*.php") as $filename) { include $filename; } */ ?> </table>
- 2 replies
-
- limit
- reduce load time
-
(and 2 more)
Tagged with: