Jump to content

[SOLVED] What to do?!?!


adam84

Recommended Posts

Alrighty, I have a search page on my site and what I want to do is when the user hits the search button. I want to build my query and all that and print out the total number of records found. But since there could be a ton of records found, I only want to display x records per page, so far no problem.

 

My question is for me to do this would I have to build two different queries,

1. First query to count the total number of records found.

2. A second query to retrieve x amount of records, using LIMIT.

 

Is this pretty much the only way of doing this??? Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/117186-solved-what-to-do/
Share on other sites

This is one of the topics where Google may be more help than a simple answer on here. You have the right of how to approach it, though. Do a search for "paginating mysql results" and you should come up with some pretty significant results to go with. Here is an idea to look at, though:

<?php
// Number of results per page
$limit = 30;

// Results page: default to page 1
$page = isset($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p'] : 1;

// Set up LIMIT clause
$offset = ($limit * $p) - $limit;

// I'm just throwing in a very simplistic query
$countQ = "SELECT COUNT(*) FROM my_table";
$resQ    = "SELECT * FROM my_table LIMIT $offset, $limit";
?>

 

I'm sure that will give you at least some direction to run with. Good luck!

Link to comment
https://forums.phpfreaks.com/topic/117186-solved-what-to-do/#findComment-602776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.