Jump to content


Photo

Help, I cant get to work a piece of code


  • Please log in to reply
2 replies to this topic

#1 Rama

Rama
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 June 2006 - 04:07 AM

guys i cant get to work a this pagination code. this source code, has not been taken from phpFreaks, but maybe someone can help me out, cause im getting really mad with this..

First, i have 3 categories in my download script.
1rst. LAW1
2nd. LAW2
3rd. OTHERS

and i make a diferent page for each categorie, for example law1.php and law2.php

the problem is that each page is counting the global number of pages..

for example. I have 60 downloads in each category, and i set the number of results per page to 30, but i go to law1.php and shows me 6 links, that is to say that shows me the 2 of law1 and the 2 of law 2 and the other 2 from others, instead of showing 2.

you undertand ?

the scripts must show me only 2 pages per categorie, but instead shows me 6...

in each page i have something like this :


html code
///// and here comes the php stuff

<?
include("dbconnect.php"); 

$limit = 30;
$indexlimit = 5;

if(!$_GET[page]) $_GET[page]=1;
$start = ($_GET[page]-1)*$limit;

function pagelinks($ispage=1,$getme = "order by id DESC"){
global $limit;
    $indb = mysql_numrows(mysql_query("SELECT * FROM downloads $getme"));
    $pagenumber = $indb / $limit;
    $pagenumber++;
    $pagecnt=1;
    while($pagecnt <= $pagenumber)
        {
        if($pagecnt == $ispage){echo "[ $pagecnt ] ";}
        else{echo "<a href=\"?page=$pagecnt\" target=_self>$pagecnt</a>\n ";}
        $pagecnt++;
        }
}

$result = mysql_query("select * from downloads WHERE category = 'law1' order by id DESC limit $start,$limit");

while($r=mysql_fetch_array($result))
{    
  
   $id=$r["id"];
   $title=$r["title"];
   $date=$r["date"];
   $link=$r["link"];
   
   //display the row
echo ("$date - <a href='download.php?id=$id'>$title</a><br>");
}

echo"<br>Page: \n";
pagelinks($_GET[page]);

?>


///////////// more html here and page ending



Please any help is much apreciated....

#2 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 11 June 2006 - 04:18 AM

$indb = mysql_numrows(mysql_query("SELECT * FROM downloads $getme"))

thats not how i do my pagination, but in this case you should do this

$indb = mysql_result(mysql_query("SELECT * FROM downloads "),0)
$pagenumber = ceil($indb / $limit);

#3 Rama

Rama
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 June 2006 - 04:41 AM

THANKS... THAT WORKED..FINE...

YOUR HELP WAS MUCH APRECIATED




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users