Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help me to Paginate this simple Script
Old 05-26-2009, 03:00 AM Help me to Paginate this simple Script
Haris's Avatar
Novice Talker

Posts: 11
Name: Ali Haris
Trades: 0
Hello!

I'm very new to PHP & MySQL. I wrote a simple script.

Here it is.
PHP Code:
<?php
require("config.php");

$result mysql_query("SELECT * FROM portfolio");

while(
$row mysql_fetch_array($result))
  {
  echo 
"<div id='project'>";
  echo 
"<h3>" $row['Name'] . "</h3>";
  echo 
$row['Snapshot'];
  echo 
"<blockquote>" $row['Details'] . "</blockquote>";
  echo 
"</div>";
  }
?>
Can anyone paginate it for me? I want display 5 result per page.
Haris is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-26-2009, 07:42 AM Re: Help me to Paginate this simple Script
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Hi there. Sorry for not being more detailed in my response but I have attached a function that I wrote literally yesterday for paging through results.

You call the function as follows;

$paging = create_paging($no_ofresults, $record_no, $record_limit, $page);

The function returns an array in the form of a <ul><li> list in a <div class="pages">.

In order to get the variables for the function you must do the following;

1. $no_ofresults is the total results in your table. Just do a query as "SELECT COUNT(id) AS total FROM... etc."
2. $record_no - this is the current record number you are browsing from. If you are on your first page then this is 0. Second page, this is 5 etc. This should be passed via the query string and retrieved using the $_GET array. So you page should look like this - 'my-page.php?record_no=0'
3. $record_limit - this is how many results you want per page (e.g. 5)
4. $page - this is the name of the current page you are on

I hope to god someone else has something a little simpler but I've found that paging through results isn't quick or easy. It requires a lot of maths and lots of trial and error.

I hope that's of some use
Attached Files
File Type: zip create_paging.inc.zip (1.1 KB, 2 views)
__________________

Please login or register to view this content. Registration is FREE
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Reply     « Reply to Help me to Paginate this simple Script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24236 seconds with 13 queries