Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 07-17-2002, 05:49 AM   #1 (permalink)
tomycon
Registered User
 
Join Date: Jul 2002
Location: Massachusetts
Posts: 6
tomycon is on a distinguished road
Question Control table display with php & Postgresql?

I'm running a small office intranet with postgresql database and accessing it with php. I'm able to contruct web pages that can add to the database and display a table with results from a query to the db. However, as the db has grown, a simple query can return 100+ legit responses, which makes for a very long scroll on the web page, not to mention printing!
How can I limit the display to 10+/- items per page, then have a button that will display next 10, or previous 10? Obviously there are tons of web sites out there that do this sort of thing, I can't seem to decipher it looking at "page source code".

any help would be great! thanks!
tomycon is offline   Reply With Quote
Old 07-17-2002, 06:59 AM   #2 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
use SQL like this

first page:
select * from TABLENAME limit 0,10;

second page:
select * from TABLENAME limit 10,10;

third page:
select * from TABLENAME limit 20,10;


i would probaly do something like this in my php:

$start = $start + 10;

pass $start from the first page to all subpages
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 07-17-2002, 07:16 AM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
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
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 05:00 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting