Jump to content

Specified number of hits per page


careym1989

Recommended Posts

Hello everyone!

 

I'm having trouble figuring out what I should do. I have a table in my database that will have tons of information, as it's recording traffic on my website. However, in my home-grown control panel, I want to be able to view all of the recorded information (what I imagine would be hundreds and hundreds of records).

 

How would I limit the number of records retrieved based on the ID per page? Additionally, how would I tell PHP to create pages of information after the first page? Obviously I could do

 

include("Connect.php");
$sql = "SELECT * FROM mytable ORDER BY id ASC LIMIT 25";
$query = mysql_query($query);

 

However, that would only show the first 25 and wouldn't let me view the pages and pages of information after those 25 hits.

 

Let me know if anyone has a solution and/or if there needs to be more clarification.

 

Appreciate it, all!

 

-Carey

Link to comment
Share on other sites

Perfect. I even hate to ask this question because you've been so helpful, but how would I go about making links to keep the pages rolling dynamically instead of me having to statically adding the number and links at the bottom?

 

Long question, probably an easy answer.

 

Thanks RussellReal!

Link to comment
Share on other sites

okay.. assuming you want ALWAYS at max 10 page links at the bottom.

 

<?

include("Connect.php");

$page = ((!is_nan($_GET['page']))? $_GET['page']:1);

$sql = "SELECT * FROM `mytable` ORDER BY `id` ASC LIMIT ".(($page - 1) * 25).",25";

$sql2 = mysql_fetch_assoc(mysql_query("SELECT count(*) As num FROM `mytable`"));

$query = mysql_query($query);

$start = ((($a = ($page - 5)) < 1)? 1:$a);

$pages = ($sql2['num'] / 25);

$end = ((($a = ($page + 4)) > $pages)? $pages:$a);

$range = range($start,$end);

$links = array();

if ($page > 1) $links[] = "<a href=\"Records.php?page=".($page - 1)."\">Prev</a>";

foreach ($range as $k => $v) {

$links[] = (($v == $page)? $v:"<a href=\"Records.php?page={$v}\">$v</a>");

}

if ($page < $pages) $links[] = "<a href=\"Records.php?page=".($page + 1)."\">Next</a>";

echo implode(" ",$links);

?>

 

THERE MAY BE A FEW ERRORS.. AS I HAVN'T TESTED THIS..

Link to comment
Share on other sites

to be honest.. I really didn't read a book.. or use any tutorials.. I just kind've browsed php.net everytime I needed to find a function lol.. also, looking @ php codes that were already written kinda made me curious as to WHAT MAKES THIS SCRIPT DO WHAT IT DOES.. basically lol

 

if you want to keep in touch,

 

heres my email/MSN: RussellonMSN [AT] hotmail.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.