Re: result set in php pagination

From: Date: Sun, 24 Jan 2010 22:32:10 +0000
Subject: Re: result set in php pagination
References: 1 2 3 4 5 6  Groups: php.db 
Request: Send a blank email to php-db+get-46789@lists.php.net to get a copy of this message
Joe Keenan wrote:
Thanks very much Bastien. I haven't the faintest idea why but that simple change in the code sorted all of this. The pagination links now follow through with the complete result set of my query. I will now have to read around this to discover why the change works.
By putting it in the url means it's not a POST variable any more, it is now a GET variable. REQUEST covers both (and more) - so if it appears in GET, it will be set to that. If it appears in POST, it'll use that instead. Also nobody's mentioned you should use mysql_real_escape_string when you do your query otherwise your site will (eventually) have problems with sql injection. $query = "SELECT article_id, author_name, category_name, title, article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM articles WHERE author_name = '$author_name' ORDER BY magazine_date ASC LIMIT $offset, $rowsperpage"; becomes: $query = "SELECT article_id, author_name, category_name, title, article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM articles WHERE author_name = '" . mysql_real_escape_string($author_name) . "' ORDER BY magazine_date ASC LIMIT $offset, $rowsperpage"; You won't see much difference if you print it out but if you put things like a single quote in your name search, it will be handled now and not cause a mysql error. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#46789) next »