A problem with pagination in PHP

A problem with pagination in PHP

am 15.06.2011 10:30:10 von Taco Mathijs Hillenaar-Meerveld

--0050450142f7f6480904a5bbf5ae
Content-Type: text/plain; charset=ISO-8859-1

Hello everyone,

I have followed only a short course in PHP and have a book 'PHP for dummies'
but i can't find a solution for my problem.

I'm currently working on a photoalbum. most functions work and i started to
implement pagination on my photoalbum.
where the page script works fine when i get a list of users from the db, it
does not work the same way for my pictures.

when the page is loading all seem to work fine untill i have more than 5
photos on the page ( $showRecords)
also, when i change the second query to just load all the pictures from the
db it shows the 5 pictures AND it shows
how many pages exist.

however, im stuck here, because when i click on page 1, 2 etc it gives me a
blank page.
when the query results are over 5 pictures in my current script (as seen
below) i get an error message:

*You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ''0' , '5'' at
line 1
*
for some reason i haven't found a good solution yet. i hope some of you can
give me a hand here to understand it better.
any tips about the script and about the style are welcome, im still learning
and could use some constructive critics.

taco mathijs

> // this routine checks if a visitor has acces. no session - no acces
> if(!isset($_SESSION['gbrid'])) {
> echo "u moet ingelogd zijn als gebruiker";
> exit();
> }
>
> else {
>
> //-- link back to the last page.
> echo "

Terug
> naar het overzicht
";
>
> $pag = $_GET['pag'];
>
> // first visit should be 0
> if($pag == '' || $pag == 1){
> $pag = 0;
> }
> // results to show per page
> $showRecords= 5;
>
>
> // first query - seems to be okay. the page shows up correct
> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' && catnaam=
> '".$_GET['catnaam']."'";
>
> $results = mysql_query($query) or die(mysql_error());
> $num_rows = mysql_num_rows($results);
>
> $pages = $num_rows / $showRecords;
>
> if($pages>1){
> $myPage = $pag * $showRecords;
>
> // the second query.
> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' &&
> catnaam= '".$_GET['catnaam']."' ORDER BY fotid ASC LIMIT '".$myPage."' ,
> '".$showRecords."'";
>
>
>
> $results = mysql_query($query) or die(mysql_error());
> }
>
> if($pages > 1){
> for($i=1; $i<=floor($pages); $i++){
>
>
> echo ' | ';
> }
>
> echo " |

";
> }
>
>
>
>
> while ($rows = mysql_fetch_array($results))
> {
>
> $foto1 = ' > = ".$fotid.">";
>
> echo " > "\">".$foto1."";
>
>
>
>
>
> }
> }
>
> // for debugging purposes
> echo print_r($query);
>
>
>
>
> ?>
>

--0050450142f7f6480904a5bbf5ae--

Re: A problem with pagination in PHP

am 15.06.2011 22:35:23 von Kesavan Rengarajan

--0016e6dab53888e41e04a5c61721
Content-Type: text/plain; charset=ISO-8859-1

Try remiving the single quotes around myPage and showRecords.
On 15/06/2011 6:38 PM, "Taco Mathijs Hillenaar-Meerveld" <
tm.hillenaar@gmail.com> wrote:
> Hello everyone,
>
> I have followed only a short course in PHP and have a book 'PHP for
dummies'
> but i can't find a solution for my problem.
>
> I'm currently working on a photoalbum. most functions work and i started
to
> implement pagination on my photoalbum.
> where the page script works fine when i get a list of users from the db,
it
> does not work the same way for my pictures.
>
> when the page is loading all seem to work fine untill i have more than 5
> photos on the page ( $showRecords)
> also, when i change the second query to just load all the pictures from
the
> db it shows the 5 pictures AND it shows
> how many pages exist.
>
> however, im stuck here, because when i click on page 1, 2 etc it gives me
a
> blank page.
> when the query results are over 5 pictures in my current script (as seen
> below) i get an error message:
>
> *You have an error in your SQL syntax; check the manual that corresponds
to
> your MySQL server version for the right syntax to use near ''0' , '5'' at
> line 1
> *
> for some reason i haven't found a good solution yet. i hope some of you
can
> give me a hand here to understand it better.
> any tips about the script and about the style are welcome, im still
learning
> and could use some constructive critics.
>
> taco mathijs
>
> >> // this routine checks if a visitor has acces. no session - no acces
>> if(!isset($_SESSION['gbrid'])) {
>> echo "u moet ingelogd zijn als gebruiker";
>> exit();
>> }
>>
>> else {
>>
>> //-- link back to the last page.
>> echo "

Terug
>> naar het overzicht
";
>>
>> $pag = $_GET['pag'];
>>
>> // first visit should be 0
>> if($pag == '' || $pag == 1){
>> $pag = 0;
>> }
>> // results to show per page
>> $showRecords= 5;
>>
>>
>> // first query - seems to be okay. the page shows up correct
>> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' &&
catnaam=
>> '".$_GET['catnaam']."'";
>>
>> $results = mysql_query($query) or die(mysql_error());
>> $num_rows = mysql_num_rows($results);
>>
>> $pages = $num_rows / $showRecords;
>>
>> if($pages>1){
>> $myPage = $pag * $showRecords;
>>
>> // the second query.
>> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' &&
>> catnaam= '".$_GET['catnaam']."' ORDER BY fotid ASC LIMIT '".$myPage."' ,
>> '".$showRecords."'";
>>
>>
>>
>> $results = mysql_query($query) or die(mysql_error());
>> }
>>
>> if($pages > 1){
>> for($i=1; $i<=floor($pages); $i++){
>>
>>
>> echo ' | ';
>> }
>>
>> echo " |

";
>> }
>>
>>
>>
>>
>> while ($rows = mysql_fetch_array($results))
>> {
>>
>> $foto1 = ' >> = ".$fotid.">";
>>
>> echo " >> "\">".$foto1."";
>>
>>
>>
>>
>>
>> }
>> }
>>
>> // for debugging purposes
>> echo print_r($query);
>>
>>
>>
>>
>> ?>
>>

--0016e6dab53888e41e04a5c61721--

Re: A problem with pagination in PHP

am 16.06.2011 09:42:19 von Taco Mathijs Hillenaar-Meerveld

--00504502be8ba919fd04a5cf6818
Content-Type: text/plain; charset=ISO-8859-1

i have removed them and it works when i remove the $_GET on the locid and
catnaam in the first query.
it just loads all pictures from the whole table. but i only want the
pictures that not only have that certain location id but are in that
location aswell.

with the query i have now it loads the pictures but once it finds more than
5 pictures ($showRecords) it doesn't show the other pages.
only the first one.

On Wed, Jun 15, 2011 at 10:35 PM, kesavan trichy rengarajan wrote:

> Try remiving the single quotes around myPage and showRecords.
> On 15/06/2011 6:38 PM, "Taco Mathijs Hillenaar-Meerveld" <
> tm.hillenaar@gmail.com> wrote:
> > Hello everyone,
> >
> > I have followed only a short course in PHP and have a book 'PHP for
> dummies'
> > but i can't find a solution for my problem.
> >
> > I'm currently working on a photoalbum. most functions work and i started
> to
> > implement pagination on my photoalbum.
> > where the page script works fine when i get a list of users from the db,
> it
> > does not work the same way for my pictures.
> >
> > when the page is loading all seem to work fine untill i have more than 5
> > photos on the page ( $showRecords)
> > also, when i change the second query to just load all the pictures from
> the
> > db it shows the 5 pictures AND it shows
> > how many pages exist.
> >
> > however, im stuck here, because when i click on page 1, 2 etc it gives me
> a
> > blank page.
> > when the query results are over 5 pictures in my current script (as seen
> > below) i get an error message:
> >
> > *You have an error in your SQL syntax; check the manual that corresponds
> to
> > your MySQL server version for the right syntax to use near ''0' , '5'' at
> > line 1
> > *
> > for some reason i haven't found a good solution yet. i hope some of you
> can
> > give me a hand here to understand it better.
> > any tips about the script and about the style are welcome, im still
> learning
> > and could use some constructive critics.
> >
> > taco mathijs
> >
> > > >> // this routine checks if a visitor has acces. no session - no acces
> >> if(!isset($_SESSION['gbrid'])) {
> >> echo "u moet ingelogd zijn als gebruiker";
> >> exit();
> >> }
> >>
> >> else {
> >>
> >> //-- link back to the last page.
> >> echo "

Terug
> >> naar het overzicht
";
> >>
> >> $pag = $_GET['pag'];
> >>
> >> // first visit should be 0
> >> if($pag == '' || $pag == 1){
> >> $pag = 0;
> >> }
> >> // results to show per page
> >> $showRecords= 5;
> >>
> >>
> >> // first query - seems to be okay. the page shows up correct
> >> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' &&
> catnaam=
> >> '".$_GET['catnaam']."'";
> >>
> >> $results = mysql_query($query) or die(mysql_error());
> >> $num_rows = mysql_num_rows($results);
> >>
> >> $pages = $num_rows / $showRecords;
> >>
> >> if($pages>1){
> >> $myPage = $pag * $showRecords;
> >>
> >> // the second query.
> >> $query = "SELECT * FROM fot WHERE locid= '" .$_GET['locid']."' &&
> >> catnaam= '".$_GET['catnaam']."' ORDER BY fotid ASC LIMIT '".$myPage."' ,
> >> '".$showRecords."'";
> >>
> >>
> >>
> >> $results = mysql_query($query) or die(mysql_error());
> >> }
> >>
> >> if($pages > 1){
> >> for($i=1; $i<=floor($pages); $i++){
> >>
> >>
> >> echo ' | ';
> >> }
> >>
> >> echo " |

";
> >> }
> >>
> >>
> >>
> >>
> >> while ($rows = mysql_fetch_array($results))
> >> {
> >>
> >> $foto1 = ' > >> = ".$fotid.">";
> >>
> >> echo " > >> "\">".$foto1."";
> >>
> >>
> >>
> >>
> >>
> >> }
> >> }
> >>
> >> // for debugging purposes
> >> echo print_r($query);
> >>
> >>
> >>
> >>
> >> ?>
> >>
>

--00504502be8ba919fd04a5cf6818--