Navigation Help

--0-141590419-1212593019=:87821
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,=0ACould any one please help me with Page Navigation. I have done Next a=
nd Previous page Navigation but confused on printing page numbers (1,2,3,4)=
and hyperlink them. Below is the code which i'm halfway on but it only pri=
nts "1" with no hyperlink where as I have 11 pages, if i print $noPages.=0A=
Could you please correct where i'm mistaking.=0A=A0$result =3D safe_query("=
select count(*) FROM gig g, venue v WHERE g.gigName LIKE '%".$gig_name."%' =
");=0A=A0$noEntries =3D mysql_num_rows($result);=0A=A0$noPages =3D ceil($no=
Entries / $limit);=0A=A0=A0$currentPage =3D 0;=0A=A0if(isset($_GET['pag']) =
&& =0A=A0=A0=A0 is_numeric($_GET['pag']) && =0A=A0=A0=A0 $_GET['pag'] > 0 &=
& =0A=A0=A0=A0 $_GET['pag'] < $noPages){=0A=A0=A0=A0=A0=0A=A0=A0=A0=A0=A0=
=A0=A0 $currentPage =3D $_GET['pag'];=0A=A0}=0A=A0$start =3D $currentPage *=
$pageLimit;=0A=A0=A0$sqlTotal =3D "select * FROM gig g, venue v WHERE g.gi=
gName LIKE '%".$gig_name."%' ".$start.",".$limit;=0A=A0for($a =3D 0; $a < $=
noPages; $a++){=0A=A0=A0=A0 if($currentPage =3D=3D $a){ =0A=A0=A0=A0=A0=A0=
=A0=A0 echo($a+1);=0A=A0=A0=A0 }else{=0A=A0=A0=A0=A0=A0=A0=A0 echo '<a href=
=3D"'.$_SERVER['PHP_SELF'].'?spag=3D'.$a.'">'.($a+1).'</a>';=0A=A0=A0=A0 }=
=0A=A0=A0=A0 if($a < $noPages - 1){=0A=A0=A0=A0=A0=A0=A0=A0 echo '-';=0A=A0=
=A0=A0 }=0A}=0A=0A=0A
--0-141590419-1212593019=:87821--
Nasreen Laghari [ Mi, 04 Juni 2008 17:23 ] [ ID #1955018 ]

Re: Navigation Help

> $result = safe_query("select count(*) FROM gig g, venue v WHERE g.gigName LIKE '%".$gig_name."%' ");
> $noEntries = mysql_num_rows($result);
> $noPages = ceil($noEntries / $limit);

$noEntries is always going to be 1 - there is a single row with the
'count' in it.

What you probably want is:

$result = safe_query('select count(*) AS count from ... ....');
$noEntries = mysql_fetch_assoc($result['count']);

or

// since we're not 'aliasing' the result, i dont know what it will be
called in the $row array.
// so just pop it.

$result = safe_query("select count(*) from ...";
$row = mysql_fetch_assoc($result);
$noEntries = array_pop($row);

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
dmagick [ Do, 05 Juni 2008 03:34 ] [ ID #1955219 ]
PHP » gmane.comp.php.database » Navigation Help

Vorheriges Thema: Working with "time" data from MYSQL
Nächstes Thema: authentication verification