Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,047 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,538 people online right now. Registration is fast and FREE... Join Now!




Paging data from database with PHP

 
Reply to this topicStart new topic

Paging data from database with PHP, Showing records in colums?

43420
2 Aug, 2008 - 08:24 PM
Post #1

New D.I.C Head
*

Joined: 2 Aug, 2008
Posts: 5

Hi,
I'm a PHP/MySQL newbie. I have been reading a lot of PHP pagination tutorials and I noticed that most of them teach you how to show your records one after another "down" the page in rows and then after they've reached a certain limit the code will generate a new page for the overflowing records.
To better explain I've just copied this snippet from one of the tutorials I was reading:

CODE

// Start paging variables
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];
$rows_per_page=5; // number of records per page
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page); // calculate number of pages required

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page; // determine start record
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query ." . mysql_error());


I was wondering whether it was possible have the records showing one after another "across" the page (like in columns) and then when it reaches a certain limit, it breaks and then goes to the next line - showing another batch of records until it reaches the limit for that line and then breaks and goes to next line.... etc then after the limit of rows allowed for that page is reached it will THEN generate a new page for the overflowing records.

Sorry if my explanation is a bit fuzzy.
I basically want to learn how to have my data shown like on this page of Celestial Star: http://celestial-star.net/renders/.

That's where I got the idea from.
Any help would be greatly appreciated.
Thank You for reading!
User is offlineProfile CardPM
+Quote Post

jwwicks
RE: Paging Data From Database With PHP
2 Aug, 2008 - 10:28 PM
Post #2

D.I.C Head
Group Icon

Joined: 31 Jul, 2008
Posts: 59



Thanked: 6 times
Dream Kudos: 200
My Contributions
Hello,

QUOTE(43420 @ 2 Aug, 2008 - 08:24 PM) *


Hi,

I was wondering whether it was possible have the records showing one after another "across" the page (like in columns) and then when it reaches a certain limit, it breaks and then goes to the next line - showing another batch of records until it reaches the limit for that line and then breaks and goes to next line.... etc then after the limit of rows allowed for that page is reached it will THEN generate a new page for the overflowing records.


Sure just change the calculation for $pages to...

CODE

$rows_per_page=5; // number of records per page
$cols_per_row=2;
$records_per_page = $rows_per_page*$cols_per_row;
//....
$pages = ceil($total_records / $records_per_page); // calculate number of pages required


The just change the query...

CODE

if (!isset($screen))
$screen=0;
$start = $screen * $records_per_page; // determine start record
$query .= "LIMIT $start, $records_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query ." . mysql_error());


Then build the HTML table...

JW



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:26PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month