Navigation Help

Navigation Help

am 04.06.2008 17:23:39 von Nasreen Laghari

--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.  $result =3D safe_query("=
select count(*) FROM gig g, venue v WHERE g.gigName LIKE '%".$gig_name."%' =
");  $noEntries =3D mysql_num_rows($result);  $noPages =3D ceil($no=
Entries / $limit);  =A0$currentPage =3D 0;  if(isset($_GET['pag']) =
&&     is_numeric($_GET['pag']) &&     $_GET['pag'] > 0 &=
&     $_GET['pag'] < $noPages){          =A0=
   $currentPage =3D $_GET['pag'];  }  $start =3D $currentPage *=
$pageLimit;  =A0$sqlTotal =3D "select * FROM gig g, venue v WHERE g.gi=
gName LIKE '%".$gig_name."%' ".$start.",".$limit;  for($a =3D 0; $a < $=
noPages; $a++){     if($currentPage == $a){      =
   echo($a+1);     }else{         echo ' =3D"'.$_SERVER['PHP_SELF'].'?spag=3D'.$a.'">'.($a+1).'';     }=
    if($a < $noPages - 1){         echo '-';  =
   }=0A} =0A
--0-141590419-1212593019=:87821--

Re: Navigation Help

am 05.06.2008 03:34:40 von dmagick

> $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