Re: [PHP-DB] Paging

2009-05-13 Thread Bastien Koert
On Mon, May 11, 2009 at 9:07 PM, Joey Hendricks
wrote:

> Hi everybody, I have a paging question. I have a page where you can view a
> persons 'profile'. And I have a list taken from the db of there books. I can
> get all the books on one page but I can't figure out the WHERE from the get.
> This is what I tried but it didn't work.
> $query   = "SELECT COUNT(*) AS numrows FROM tabs WHERE user_name='".$_GET
> ['user_name']."';
>  $data  = mysqli_query($dbc, $query) or die('Error, query failed');
>  $row = mysqli_fetch_array($data);
>  $numrows = $row['numrows'];
>
> When I do this it shows a second page but when I click on the next page It
> goes to my profile or the user who is logged in, not the users profile I was
> looking at on page 1. Thanks every one for all your help!!



Can you post the code snippets for the sections that matter?

Also, have a look at the variables you are calling, maybe one is overwriting
the other

-- 

Bastien

Cat, the other other white meat


[PHP-DB] Paging

2009-05-11 Thread Joey Hendricks
Hi everybody, I have a paging question. I have a page where you can view a 
persons 'profile'. And I have a list taken from the db of there books. I can 
get all the books on one page but I can't figure out the WHERE from the get. 
This is what I tried but it didn't work.
$query   = "SELECT COUNT(*) AS numrows FROM tabs WHERE user_name='".$_GET 
['user_name']."';
 $data  = mysqli_query($dbc, $query) or die('Error, query failed');
 $row = mysqli_fetch_array($data);
 $numrows = $row['numrows'];

When I do this it shows a second page but when I click on the next page It goes 
to my profile or the user who is logged in, not the users profile I was looking 
at on page 1. Thanks every one for all your help!!

RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Peter Beckman
On Fri, 13 Feb 2004, Robert Twitty wrote:

> If you are not opearating in a stateless environment, then you could use a
> cursor.  The web is a stateless environment, and therefore the record set
> needs to be cached either to disk or memeory.  The other alternative is to
> rerun the query for each page request.  Using disk space to store query
> results for the purpose of paging over the web is commonly done by search
> engines, and even some database engines use disk space for cursor
> implementation.  I agree that using session variables for this purpose is
> not ideal, but what's the alternative in PHP?  Storing only the
> identifiers instead of all the data significantly lessons the impact.
>
> I agree, it should be avoided if possible.

If you are running it out of a DB, limiting the results to result 1-10 or
91-100 is pretty fast; caching results seems like more of a headache to me,
and depending on how loaded your DB is, not worth the effort.

If the query takes 3-5 seconds, then either your DB is configured wrong (no
indexes), or your SQL is not written well, or you should consider some sort
of DB query caching.  Look to the manual for that.

---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

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



RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Paul Miller
One way that I have found - but never used is...

http://sqlrelay.sourceforge.net/

It can cache result sets in a file for later use.  You can then use It
does a whole bunch of other stuff too.  I really need to install this
and start working with it.

- Paul

-Original Message-
From: Robert Twitty [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 13, 2004 1:59 PM
To: Paul Miller
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Paging large recordsets


If you are not opearating in a stateless environment, then you could use
a cursor.  The web is a stateless environment, and therefore the record
set needs to be cached either to disk or memeory.  The other alternative
is to rerun the query for each page request.  Using disk space to store
query results for the purpose of paging over the web is commonly done by
search engines, and even some database engines use disk space for cursor
implementation.  I agree that using session variables for this purpose
is not ideal, but what's the alternative in PHP?  Storing only the
identifiers instead of all the data significantly lessons the impact.

I agree, it should be avoided if possible.

-- bob

On Fri, 13 Feb 2004, Paul Miller wrote:

> In no way I am trying start some long thread here.  But I have always 
> heard it was bad to store that much data in a session array?  I could 
> just be really off here and not understanding what I have read.  I 
> know PHP stores the sessions as text files.  The only reason I can 
> come up with why one should not store large amounts of data would be 
> disk write/read speed per user.
>
> Can someone clarify this for me?
>
> - Paul
>
> -Original Message-
> From: Robert Twitty [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 13, 2004 12:34 PM
> To: Karen Resplendo
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Paging large recordsets
>
>
> Most of the PHP solutions I have seeen require the use of session 
> variables.  You could create an array containing only the unique 
> identifiers of all the records, and then store it into a session 
> variable. You would then use another session variable to retain the 
> page size, and then include the page numbers in the "Next", "Prev", 
> "First", "Last" and "Absolutr" page links.  Printing is probably best 
> done with dynamically generated PDF instead of HTML.
>
> -- bob
>
> On Fri, 13 Feb 2004, Karen Resplendo wrote:
>
> > I guess the time has come that my boss wants "Next", "Previous", 
> > "First", "Last" paging for our data displays of large recordsets or 
> > datasets.
> >
> > Any good solutons out there already? I have pieces of a few 
> > examples.
> >
> > Also, how to deal with printing? I would assume that the ideal page 
> > size is not the ideal printed page size. oi vay!
> >
> > TIA
> >
> >
> > -
> > Do you Yahoo!?
> > Yahoo! Finance: Get your refund fast by filing online
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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



RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Robert Twitty
If you are not opearating in a stateless environment, then you could use a
cursor.  The web is a stateless environment, and therefore the record set
needs to be cached either to disk or memeory.  The other alternative is to
rerun the query for each page request.  Using disk space to store query
results for the purpose of paging over the web is commonly done by search
engines, and even some database engines use disk space for cursor
implementation.  I agree that using session variables for this purpose is
not ideal, but what's the alternative in PHP?  Storing only the
identifiers instead of all the data significantly lessons the impact.

I agree, it should be avoided if possible.

-- bob

On Fri, 13 Feb 2004, Paul Miller wrote:

> In no way I am trying start some long thread here.  But I have always
> heard it was bad to store that much data in a session array?  I could
> just be really off here and not understanding what I have read.  I know
> PHP stores the sessions as text files.  The only reason I can come up
> with why one should not store large amounts of data would be disk
> write/read speed per user.
>
> Can someone clarify this for me?
>
> - Paul
>
> -Original Message-
> From: Robert Twitty [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 13, 2004 12:34 PM
> To: Karen Resplendo
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Paging large recordsets
>
>
> Most of the PHP solutions I have seeen require the use of session
> variables.  You could create an array containing only the unique
> identifiers of all the records, and then store it into a session
> variable. You would then use another session variable to retain the page
> size, and then include the page numbers in the "Next", "Prev", "First",
> "Last" and "Absolutr" page links.  Printing is probably best done with
> dynamically generated PDF instead of HTML.
>
> -- bob
>
> On Fri, 13 Feb 2004, Karen Resplendo wrote:
>
> > I guess the time has come that my boss wants "Next", "Previous",
> > "First", "Last" paging for our data displays of large recordsets or
> > datasets.
> >
> > Any good solutons out there already? I have pieces of a few examples.
> >
> > Also, how to deal with printing? I would assume that the ideal page
> > size is not the ideal printed page size. oi vay!
> >
> > TIA
> >
> >
> > -
> > Do you Yahoo!?
> > Yahoo! Finance: Get your refund fast by filing online
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Peter Beckman

On Fri, 13 Feb 2004, Paul Miller wrote:

> I have always heard it was bad to store that much data in a session array?
>
> Can someone clarify this for me?

IMO It is bad to store lots of data in session variables.

The $_REQUEST var for the post/get should be enough.

URL: search.php?page=10

code:

$conf['maxresultsperpage'] = 10;

$ref = mysql_query("select count(*) as c from table where subject like '%foo%'");
list($cnt) = mysql_fetch_array($ref); // will assoc work here?  dunno, didn't test
echo "Displaying ".($conf['maxresultsperpage']*$_REQUEST['page'])-9." through 
".($conf['maxresultsperpage']*$_REQUEST['page']).".";
$ref = mysql_query("select subject, data from table where subject like '%foo%' 
limit ".$conf['maxresultsperpage'].", 
".($conf['maxresultsperpage']*$_REQUEST['page'])-10);

// loop through array returned from mysql

echo "Next";

 I think.  It might need some tweaking, but you get the idea (I hope).

 No need to store variables here.

Beckman

> -Original Message-
> From: Robert Twitty [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 13, 2004 12:34 PM
> To: Karen Resplendo
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Paging large recordsets
>
>
> Most of the PHP solutions I have seeen require the use of session
> variables.  You could create an array containing only the unique
> identifiers of all the records, and then store it into a session
> variable. You would then use another session variable to retain the page
> size, and then include the page numbers in the "Next", "Prev", "First",
> "Last" and "Absolutr" page links.  Printing is probably best done with
> dynamically generated PDF instead of HTML.
>
> -- bob
>
> On Fri, 13 Feb 2004, Karen Resplendo wrote:
>
> > I guess the time has come that my boss wants "Next", "Previous",
> > "First", "Last" paging for our data displays of large recordsets or
> > datasets.
> >
> > Any good solutons out there already? I have pieces of a few examples.
> >
> > Also, how to deal with printing? I would assume that the ideal page
> > size is not the ideal printed page size. oi vay!
> >
> > TIA
> >
> >
> > -
> > Do you Yahoo!?
> > Yahoo! Finance: Get your refund fast by filing online
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

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



RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Paul Miller
In no way I am trying start some long thread here.  But I have always
heard it was bad to store that much data in a session array?  I could
just be really off here and not understanding what I have read.  I know
PHP stores the sessions as text files.  The only reason I can come up
with why one should not store large amounts of data would be disk
write/read speed per user.

Can someone clarify this for me?

- Paul

-Original Message-
From: Robert Twitty [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 13, 2004 12:34 PM
To: Karen Resplendo
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Paging large recordsets


Most of the PHP solutions I have seeen require the use of session
variables.  You could create an array containing only the unique
identifiers of all the records, and then store it into a session
variable. You would then use another session variable to retain the page
size, and then include the page numbers in the "Next", "Prev", "First",
"Last" and "Absolutr" page links.  Printing is probably best done with
dynamically generated PDF instead of HTML.

-- bob

On Fri, 13 Feb 2004, Karen Resplendo wrote:

> I guess the time has come that my boss wants "Next", "Previous", 
> "First", "Last" paging for our data displays of large recordsets or 
> datasets.
>
> Any good solutons out there already? I have pieces of a few examples.
>
> Also, how to deal with printing? I would assume that the ideal page 
> size is not the ideal printed page size. oi vay!
>
> TIA
>
>
> -
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing online

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

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



RE: [PHP-DB] Paging large recordsets

2004-02-13 Thread Hutchins, Richard
I know phpclasses.org has a few recordset paging classes out there for your
convenience. Might want to try on a couple of those too just to see if they
fit.

Rich

> -Original Message-
> From: Robert Twitty [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 13, 2004 1:34 PM
> To: Karen Resplendo
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Paging large recordsets
> 
> 
> Most of the PHP solutions I have seeen require the use of session
> variables.  You could create an array containing only the unique
> identifiers of all the records, and then store it into a 
> session variable.
> You would then use another session variable to retain the 
> page size, and
> then include the page numbers in the "Next", "Prev", "First", 
> "Last" and
> "Absolutr" page links.  Printing is probably best done with 
> dynamically
> generated PDF instead of HTML.
> 
> -- bob
> 
> On Fri, 13 Feb 2004, Karen Resplendo wrote:
> 
> > I guess the time has come that my boss wants "Next", 
> "Previous", "First", "Last" paging for our data displays of 
> large recordsets or datasets.
> >
> > Any good solutons out there already? I have pieces of a few 
> examples.
> >
> > Also, how to deal with printing? I would assume that the 
> ideal page size is not the ideal printed page size. oi vay!
> >
> > TIA
> >
> >
> > -
> > Do you Yahoo!?
> > Yahoo! Finance: Get your refund fast by filing online
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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



Re: [PHP-DB] Paging large recordsets

2004-02-13 Thread Robert Twitty
Most of the PHP solutions I have seeen require the use of session
variables.  You could create an array containing only the unique
identifiers of all the records, and then store it into a session variable.
You would then use another session variable to retain the page size, and
then include the page numbers in the "Next", "Prev", "First", "Last" and
"Absolutr" page links.  Printing is probably best done with dynamically
generated PDF instead of HTML.

-- bob

On Fri, 13 Feb 2004, Karen Resplendo wrote:

> I guess the time has come that my boss wants "Next", "Previous", "First", "Last" 
> paging for our data displays of large recordsets or datasets.
>
> Any good solutons out there already? I have pieces of a few examples.
>
> Also, how to deal with printing? I would assume that the ideal page size is not the 
> ideal printed page size. oi vay!
>
> TIA
>
>
> -
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing online

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



Re: [PHP-DB] Paging large recordsets

2004-02-13 Thread Peter Beckman
On Fri, 13 Feb 2004, Karen Resplendo wrote:

> I guess the time has come that my boss wants "Next", "Previous", "First",
> "Last" paging for our data displays of large recordsets or datasets.

 First, do a query to find out how many rows.

 select count(*) from table where (your where clauses for the query);

 That's your # of records.

 Then do:

 select count(*) from table where (your clauses) limit 
($pagenum*$itemlimit)-$itemlimit), $itemlimit;

 so if your $itemlimit = 10 items per page, and you are on page 3,

 it would be ... limit 20, 10

 page #1, limit 0,10 etc

> Also, how to deal with printing? I would assume that the ideal page size
> is not the ideal printed page size. oi vay!

 In IE 6, this works:

 

 Even if your text follows, IE will print a page break.  Haven't researched
 how to do it in Mozilla or Netscape.

Beckman
---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

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



[PHP-DB] Paging large recordsets

2004-02-13 Thread Karen Resplendo
I guess the time has come that my boss wants "Next", "Previous", "First", "Last" 
paging for our data displays of large recordsets or datasets.
 
Any good solutons out there already? I have pieces of a few examples.
 
Also, how to deal with printing? I would assume that the ideal page size is not the 
ideal printed page size. oi vay!
 
TIA


-
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online

Re: [PHP-DB] Paging help needed :-(

2001-07-12 Thread Roger Ramirez

Here is some code that I like to use.  I mix real code and psuedo code cause
I'm more used to just using the db class from PHP Lib.

First get a count of how many records there are.

$sql = "SELECT count(*) as c FROM users";
Then read that count into variable $count.

Declare a variable which will contain the number of records per page, this
is a really good idea cause if that number changes later you just have to
change one variable instead of hunting down every instance of that number.

$records_per_page = 10;

Next figure out how many pages you'll have.

$total_pages = ceil( $count / $records_per_page );

This just sets up a page variable which will be past in a "next" and "prev"
link.  The first link to this page may not actually have $page so this just
sets it up.
if ( !isset($page) ) { $page = 1; }

I like to setup a little navigation that has "First | Prev | Next | Last" on
the page with each word being a link or not depending on what page you are
on.  To do this I use the following piece of code.

# this will set up the "First | Prev | " part of our navigation.
if ( $page == 1 ) {
# if we are on the first page then "First" and "Prev"
# should not be links.
$naviagation = "First | Prev | ";
} else {
# we are not on page one so "First" and "Prev" can
# be links
$prev_page = $page - 1;
$navigation = "First | Prev | ";
}

# this part will set up the rest of our navigation "Next | Last"
if ( $page == $total_pages ) {
# we are on the last page so "Next" and "Last"
# should not be links
$navigation .= "Next | Last";
} else {
# we are not on the last page so "Next" and "Last"
# can be links
$next_page = $page + 1;
$navigation .= "Next | Last";
}

With your navigation built you can just echo that out any where you want it
to appear.

The final thing to do is your actual query, but first we have to figure out
what the offset will be.

$offset = ( $page - 1 ) * $total_pages;
$sql = "SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC
LIMIT $offset,$records_per_page";

And that's it?  Simple eh?

You may also want to put out something like: echo "$page of $total_pages";

Enjoy.

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 12, 2001 3:49 AM
Subject: [PHP-DB] Paging help needed :-(


Hi there Everyone,

I currently have a dedicated Apache server with PHP 4.06, MySQL etc ..
installed and running fine.  Below is alittle peice of code that I would
love an answer to:





then all the HTML and display bits (Example at www.planetoxygene.com in the
guestbook).



Now my question is, how do I do paging in PHP?  I need to display 10 entries
per page, and be able to go back and forth with them.  I'm relatively new to
PHP so I would be really grateful for any advice.

Thanks everyone, I appreciate it.

Chris Payne
www.planetoxygene.com




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Paging help needed :-(

2001-07-11 Thread Dobromir Velev

Hi,

First you'll have to modify your query to show only ten rows.

$sql = "SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC LIMIT $start,10";

The $start variable shows the number of the first row to show

The links for the previous and next page will be something like this

=10)echo "Previous";
echo "Next";
?>

You can play around with this code to allow the users to go directly to a
specific page, not to show the "Next" link when there are no more records to
show, allow users to define how many records to show in a page and etc.

Dobromir Velev

-Original Message-
From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, July 12, 2001 7:53 AM
Subject: [PHP-DB] Paging help needed :-(


Hi there Everyone,

I currently have a dedicated Apache server with PHP 4.06, MySQL etc ..
installed and running fine.  Below is alittle peice of code that I would
love an answer to:





then all the HTML and display bits (Example at www.planetoxygene.com in the
guestbook).



Now my question is, how do I do paging in PHP?  I need to display 10 entries
per page, and be able to go back and forth with them.  I'm relatively new to
PHP so I would be really grateful for any advice.

Thanks everyone, I appreciate it.

Chris Payne
www.planetoxygene.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Paging help needed :-(

2001-07-11 Thread chris

Hi there Everyone,

I currently have a dedicated Apache server with PHP 4.06, MySQL etc .. installed and 
running fine.  Below is alittle peice of code that I would love an answer to:





then all the HTML and display bits (Example at www.planetoxygene.com in the guestbook).



Now my question is, how do I do paging in PHP?  I need to display 10 entries per page, 
and be able to go back and forth with them.  I'm relatively new to PHP so I would be 
really grateful for any advice.

Thanks everyone, I appreciate it.

Chris Payne
www.planetoxygene.com