View Single Post
Old 07-17-2002, 07:16 AM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
redhead is on a distinguished road
This is what I do:
Code:
function reducer($where)
{
   global $argv;
   $argv_intern = implode($argv,"+");
   if(!ereg("startat=", implode($argv, "+")))
     return $argv_intern."&startat=$where";
   return ereg_replace("startat=[0-9]*", "startat=$where", $argv_intern);
}

function print_links($lang="uk", $full="0", $order="id")
{
  global $DB_LINK, $PHP_SELF, $startat;
  if(!isset($startat))
    $startat = 0;
  $limitquery="$startat, 10";
  $res=mysql_query("SELECT * FROM links WHERE countable = 0 ORDER BY $order DESC LIMIT $limitquery", $DB_LINK);  
  $size=mysql_num_rows($res);
  if($size != 0)
  {
    $limiter=10;
    if(!$full)
    {
      echo "<table border='0' cellspacing='1' cellpadding='1'>";
    }
    while($myrow=mysql_fetch_array($res))
    { 
       $pres = mysql_query("SELECT display_name FROM user WHERE id=$myrow[user_id]", $DB_LINK);
       $row = mysql_fetch_array($pres);
       print_links_entry($lang, $myrow[id], $myrow[created_date], $myrow[url], $myrow[description], $myrow[$user_id], $row[display_name], $myrow[click_count], $full);
    }
    if($full == 1)
    {
      echo "<br><font size='-1'><center>";
       if($startat > 0) 
       {
         echo "<a href='$PHP_SELF?".reducer($startat-$limiter)."'>";
         if($lang == "da")
           echo "$limiter Forige links</a>";
         else
           echo "Previus $limiter links</a>";
       }
       if(($startat+$limiter) == $size)
       {
         echo "<a href ='$PHP_SELF?".reducer($startat+$limiter)."'>";
         if($lang == "da")
           echo " &nbsp;  &nbsp; $limiter Nęste links</a></font>";
         else
           echo " &nbsp;  &nbsp; Next $limiter links</a></font>";
       }
       echo "</center>";
    }
    if(!$full)
    {
      echo "</table>";
    }
  }
  else
  {
     echo "
         <font size='+1'>
          <p>
          There wasn't found any entries.
          <p>
         </font>
         ";
  }
}
Just to give you a hint... As Admin said, its the $startat combined with the sql-function LIMIT

Now this is not directed towards a postgreSQL database, but I think php uses a psql_* function intead of mysql_*
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote