Re: [PHP] Multiple pages of data.

2004-09-29 Thread Silvio Porcellana
You can solve it totally with SQL, using the FOUND_ROWS() function 
[http://dev.mysql.com/doc/mysql/en/Information_functions.html]

I think this is the most efficient way of doing it...
HTH, cheers
Silvio Porcellana
Nick Patsaros wrote:
I'm trying to build a bulletin style system right now.  I have topics
and replies to each topic.  If a topic gets more than 15 replies I
want them to start carrying over onto page 2 and then 3 and so on with
15 replies per page.
The key that I'm missing I guess is, how do I keep track of the last
accessed row in the database?  So if I run a LIMIT 15 I can go back
and pick up where I left on previously?  Using the primary key isn't
going to help because if posts get deleted I would have less than 15
per page.
Maybe I'm totally lost on this though, if someone could give me a bit
of help on the most efficient way to accomplish this.
--Nick
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Multiple pages of data.

2004-09-29 Thread Graham Cossey
Prev 1 2 3 Next tutorial at phpfreaks.com:

http://www.phpfreaks.com/tutorials/73/0.php

HTH

Graham.

-Original Message-
From: Silvio Porcellana [mailto:[EMAIL PROTECTED]
Sent: 29 September 2004 10:53
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Multiple pages of data.


You can solve it totally with SQL, using the FOUND_ROWS() function 
[http://dev.mysql.com/doc/mysql/en/Information_functions.html]

I think this is the most efficient way of doing it...

HTH, cheers

Silvio Porcellana

Nick Patsaros wrote:
 I'm trying to build a bulletin style system right now.  I have topics
 and replies to each topic.  If a topic gets more than 15 replies I
 want them to start carrying over onto page 2 and then 3 and so on with
 15 replies per page.
 
 The key that I'm missing I guess is, how do I keep track of the last
 accessed row in the database?  So if I run a LIMIT 15 I can go back
 and pick up where I left on previously?  Using the primary key isn't
 going to help because if posts get deleted I would have less than 15
 per page.
 
 Maybe I'm totally lost on this though, if someone could give me a bit
 of help on the most efficient way to accomplish this.
 
 --Nick
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Multiple pages of data.

2004-09-28 Thread Nick Patsaros
I'm trying to build a bulletin style system right now.  I have topics
and replies to each topic.  If a topic gets more than 15 replies I
want them to start carrying over onto page 2 and then 3 and so on with
15 replies per page.

The key that I'm missing I guess is, how do I keep track of the last
accessed row in the database?  So if I run a LIMIT 15 I can go back
and pick up where I left on previously?  Using the primary key isn't
going to help because if posts get deleted I would have less than 15
per page.

Maybe I'm totally lost on this though, if someone could give me a bit
of help on the most efficient way to accomplish this.

--Nick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple pages of data.

2004-09-28 Thread Jason Davidson
Your not totally lost on it, your very cloes to your solution.  Keep
track of the LIMITs with php, and not mysql.  Pass the LIMIT
information to the next page, and use some aritihitc to determine the
next  and prvious limits for the link...
so you would have a var called $limit possibly, and your next and
previous links will pass this var + or - the number of posts per page,
so next would be $limit + 15..

Jason

Nick Patsaros [EMAIL PROTECTED] wrote: 
 
 I'm trying to build a bulletin style system right now.  I have topics
 and replies to each topic.  If a topic gets more than 15 replies I
 want them to start carrying over onto page 2 and then 3 and so on with
 15 replies per page.
 
 The key that I'm missing I guess is, how do I keep track of the last
 accessed row in the database?  So if I run a LIMIT 15 I can go back
 and pick up where I left on previously?  Using the primary key isn't
 going to help because if posts get deleted I would have less than 15
 per page.
 
 Maybe I'm totally lost on this though, if someone could give me a bit
 of help on the most efficient way to accomplish this.
 
 --Nick
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple pages of data.

2004-09-28 Thread Matthew Fonda
Or if you wanted to do it all in PHP, without using LIMIT, you could do
something like this.

I'm not exactly sure how your database is set up, so I just used this
made this dummy table as the one I will use in this example:

create table topics(id int(8) not null auto_increment, topic
varchar(30), author varchar(20), body text, primary key(id));

Ok, so then I just inserted some random data into to test with.

Here is some PHP code:
?php
$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db(database, $link);
$result = mysql_query(SELECT * FROM table, $link);
$num_rows = mysql_num_rows($result);
$all = array();
while ($topic = mysql_fetch_assoc($result)) {
$all[] = $topic;
}
if (isset($_GET['start'])) {
$start =  $_GET['start'];
} else {
$start = 0;
}
for($i = $start; $i   $start + 15; $i++) {
echo Topic ID: . $all[$i]['id'] .br /;
echo Topic Title: . $all[$i]['topic'] .br /;
echo Topic Author: . $all[$i]['author'] .br /;
echo Topic Body: .  $all[$i]['body'] .br /;
echo hr;
if ($i == $start + 14) {
echo pa href=\pages.php?start=.($i+1).\Next   
 Page/a/p;
}
}
mysql_free_result($result);
mysql_close($link);
?

That will do simple paging, and works seems to work fine.


On Tue, 2004-09-28 at 22:05, Nick Patsaros wrote:
 I'm trying to build a bulletin style system right now.  I have topics
 and replies to each topic.  If a topic gets more than 15 replies I
 want them to start carrying over onto page 2 and then 3 and so on with
 15 replies per page.
 
 The key that I'm missing I guess is, how do I keep track of the last
 accessed row in the database?  So if I run a LIMIT 15 I can go back
 and pick up where I left on previously?  Using the primary key isn't
 going to help because if posts get deleted I would have less than 15
 per page.
 
 Maybe I'm totally lost on this though, if someone could give me a bit
 of help on the most efficient way to accomplish this.
 
 --Nick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple pages of data.

2004-09-28 Thread Matthew Fonda
oops, forgot to add this, put as first line in the for loop:
if ($i == $num_rows) break;

On Tue, 2004-09-28 at 22:45, Matthew Fonda wrote:
 Or if you wanted to do it all in PHP, without using LIMIT, you could do
 something like this.
 
 I'm not exactly sure how your database is set up, so I just used this
 made this dummy table as the one I will use in this example:
 
 create table topics(id int(8) not null auto_increment, topic
 varchar(30), author varchar(20), body text, primary key(id));
 
 Ok, so then I just inserted some random data into to test with.
 
 Here is some PHP code:
 ?php
 $link = mysql_connect('localhost', 'user', 'password');
 mysql_select_db(database, $link);
 $result = mysql_query(SELECT * FROM table, $link);
 $num_rows = mysql_num_rows($result);
 $all = array();
 while ($topic = mysql_fetch_assoc($result)) {
   $all[] = $topic;
 }
 if (isset($_GET['start'])) {
   $start =  $_GET['start'];
 } else {
   $start = 0;
 }
 for($i = $start; $i   $start + 15; $i++) {
   echo Topic ID: . $all[$i]['id'] .br /;
   echo Topic Title: . $all[$i]['topic'] .br /;
   echo Topic Author: . $all[$i]['author'] .br /;
   echo Topic Body: .  $all[$i]['body'] .br /;
   echo hr;
   if ($i == $start + 14) {
   echo pa href=\pages.php?start=.($i+1).\Next   
  Page/a/p;
   }
 }
 mysql_free_result($result);
 mysql_close($link);
 ?
 
 That will do simple paging, and works seems to work fine.
 
 
 On Tue, 2004-09-28 at 22:05, Nick Patsaros wrote:
  I'm trying to build a bulletin style system right now.  I have topics
  and replies to each topic.  If a topic gets more than 15 replies I
  want them to start carrying over onto page 2 and then 3 and so on with
  15 replies per page.
  
  The key that I'm missing I guess is, how do I keep track of the last
  accessed row in the database?  So if I run a LIMIT 15 I can go back
  and pick up where I left on previously?  Using the primary key isn't
  going to help because if posts get deleted I would have less than 15
  per page.
  
  Maybe I'm totally lost on this though, if someone could give me a bit
  of help on the most efficient way to accomplish this.
  
  --Nick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php