Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 71
  1. #1
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,048
    Thanks
    10
    Thanked 93 Times in 91 Posts

    pagination class

    Note , I have removed most of the comments for brevity & since its mostly straightforward anyway.
    Error checks have been removed for brevity !

    da class ...
    PHP Code:
    <?php
    /**
    * firepages.com.au - basic pagination class - see
    * http://www.firepages.com.au/pagination.htm for more information
    */
    class pager{
        var 
    $p_range    0# range to show if you dont want to show ALL pages returned
        
    var $curr       1;    # current page number
        
    var $_pages  '';     # no of pages in a recordset
        
    var $_ctl       '_p';  # default control variable name
        
    var $_req_url ='';      # url to build links with
        
    var $_req_qs ='';      # query string to build links with
        # allowed replacements for titles and links
        
    var $_t_tpls   = array('{CURRENT}','{FROM}','{TO}','{MAX}','{TOTAL}');
        var 
    $_l_tpls   = array('{LINK_HREF}','{LINK_LINK}');
        
    #when set_range() is in use
        
    var $set_from=''#min page number of returned set
        
    var $set_to='';     #max number of returned set

        
    function pager($max$pp$curr$extra='')
        {
            if(!
    is_array($extra)){
                
    $extra=array();
            }
            
    $this->_pp       $pp;
            
    $this->curr       = (int)$curr $curr  ;
            
    $this->set_from=1;//may be overriden by a set_range() paged set
            
    $this->_pages $this->set_to $this->p_range ceil$max/$pp );
            
    $this->_ctl     .= empty($extra['suffix']) ? '' $extra['suffix'] ;
            
    $this->_req_qs = isset($extra['query_string']) ?
                
    $extra['query_string'] : $_SERVER['QUERY_STRING'] ;
            
    $this->_req_url = isset($extra['php_self']) ?
                
    $extra['php_self'] : $_SERVER['PHP_SELF'] ;

        
    #check for and remove control variables from query string#
            
    if(strpos($this->_req_qs,$this->_ctl)!==false){
                
    parse_str($this->_req_qs,$arr);
                
    $tmp=array();
                unset(
    $arr[$this->_ctl]);
                    foreach(
    $arr as $k=>$v){
                        
    $tmp[]="$k=$v";
                    }
                    
    $this->_req_qs implode('&'$tmp);
                    unset(
    $tmp);
            }
            
    #vars for eye_candy not declared ~#
            
    $this->_from = (($this->curr $this->_pp) - $this->_pp) + 1;
            
    $to               = ($this->_from +  $this->_pp) -;
            
    $this->_to     = ($to $max ) ? $max $to ;
            
    $this->_total $max ;
        }

        function 
    set_range($p_range)
        {
            
    $this->p_range $p_range;
        }

        function 
    get_limit()
        {
            return (
    $this->curr $this->_pp) - $this->_pp' , '.$this->_pp;
        }

        function 
    get_limit_offset()
        {
            return (
    $this->curr $this->_pp) - $this->_pp;
        }

        function 
    get_title($format)
        {
            return 
    str_replace($this->_t_tpls,
                array(
    $this->curr$this->_from$this->_to$this->_pages$this->_total), $format);
        }

        function 
    _get_qurl()
        {
            
    $q = empty($this->_req_qs) ? '' '?'.$this->_req_qs ;
            
    $s = (substr($q01) == '?') ? '&amp;' '?' ;
            return 
    $this->_req_url $q $s $this->_ctl '=';
        }

        function 
    get_prev($format)
        {
            return 
    $this->curr ?
                
    str_replace($this->_l_tpls,array($this->_get_qurl().($this->curr -1)),$format) : '' ;
        }

        function 
    get_next($format)
        {
            return (
    $this->curr $this->_pages) ?
                
    str_replace($this->_l_tpls,array($this->_get_qurl().($this->curr +1)),$format) : '' ;
        }

        function 
    get_range($format$sep,$first='',$last='')
        {
            if(
    $this->_pages 2){
                return ;
            }
            
    $pre_url $this->_get_qurl();
            
    $lfirst $llast '' ;
            
    $min  ;
            
    $to $this->_pages ;

            if(
    $this->_pages $this->p_range){
                
    $mid ceil(($this->p_range 2));
                if((
    $this->curr $mid) >= 1){
                    
    $min $this->curr $mid;
                }
                
    $to $min + ($this->p_range-1);
                if(
    $this->_pages $to){
                    
    $llast = (!empty($last)) ?
                               
    $sep.str_replace($this->_l_tpls,array($pre_url.$this->_pages,$last),$format) : '' ;
                }
               if(
    $min 1){
                   
    $lfirst = (!empty($first) && $this->curr >) ?
                               
    str_replace($this->_l_tpls,array($pre_url.'1',$first),$format) .$sep '' ;
               }
               if(
    $to $this->_pages){
                   
    $to $this->_pages ;
               }
               
    //NEW readjust to show at least p_range links is set_range in use//
               
    if(($to $min) <  $this->p_range){
                  
    $min= ($to-$this->p_range)+1;
               }
               
    //NEW external parsers may need the correct from and to values from a set_range() limited set
               
    $this->set_from=$min;
               
    $this->set_to=$to;
            }
            for(
    $x=$min$x<=$to; ++$x){
                
    $rets[]=($this->curr!=$x)?str_replace($this->_l_tpls, array($pre_url.$x$x) , $format):$x;
            }
            return 
    $lfirst.implode($sep$rets).$llast;
        }
    }
    ?>
    This class provides only the basics of pagination , it makes no queries itself, all it does is provide you with information about the results and links to go forward and backwards through your result set.

    Its actually a good idea to keep SQL and specific database information out of your pagination class since it makes your code more reusable.
    If you have a common database abstraction class you could agregate that into such a class but I think it would still be better to subclass such a solution and keep the pagination class as pure as possible.

    Also to keep markup out of the class this class requires you pass your own formatting for page results and links, again it does make it more flexible in the long run.

    Note that to make pagination efficient you normally end up making 2 queries , 1 to fetch the count , the next to fetch the actual data for display, with a properly indexed table this is not a big ask of the DB.

    example basic usage...

    Ideally you would use a function or create a subclass of the pager class to make the usage `neater` , its quite easy to wrap the above up for quicker coding.
    The following example is at its most basic.
    PHP Code:
    <?php
    //find out the size of our recordset , only fetch a count, in this query nothing else
    $max mysql_resultmysql_query("SELECT COUNT(id) FROM table WHERE id > 0"), ) ;
    $pager = new pager
        
    $max ,                     /*see above*/
        
    10 ,                         /*how many records to display at one time*/
        
    @$_GET['_p']  /*this is the current page no carried via _GET*/
        
    ) ;

    /*
    optionally set a maximum number of pages to display
    so you dont end up with 100's of links
    */
    $pager->set_range(10);

    /*the main query note the same WHERE conditions*/
    $q mysql_query("SELECT id,name FROM table WHERE id > 0 LIMIT ".$pager->get_limit());

    /*show something for your troubles*/
    echo $pager->get_title('Page {CURRENT} of {MAX}<br />Displaying results {FROM} to {TO} of {TOTAL}'). ' <br />';
    echo 
    $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ').'<br /><br />';

    /*+ of course the actual data*/
    while($r mysql_fetch_assoc($q)){
        echo 
    "{$r['id']},{$r['name']}<br />";
    }
    ?>
    any feedback , suggestions, glaring errors etc appreciated.

    22/01/2005
    changed '&' to &amp; (Rich Pedley)
    Added optional 'first' and 'last' links to get_range , first and last links only get shown if requested and is a first and last link is actually relevant....
    PHP Code:
    echo $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ','First','Last').'<br /><br />';
    //these could also be images/anything '<img src="first.jpg" />' etc 
    10/02/2005
    Added get_prev() and get_next() for page by page navigation,
    this did mean a change elsewhere in the class (gave get_qurl its own function) so if you are using a modified version check first.
    PHP Code:
        echo $pager->get_prev('<a href="{LINK_HREF}">Prev</a>');
        echo 
    $pager->get_next('<a href="{LINK_HREF}">text or image here</a>'); 
    17/02/1006
    Fixed borked display when using get_range();
    Added get_offset_limit() which returns the current offset for databases that can't handle the comma returned in get_limit()

    5/5/2007
    Added $pager->set_from & $pager->set_to variables for external routines that need to know the first and last page numbers of a set when using set_range();

    5/5/2007
    now displays a minimum of (e.g. with $pager->set_range(10)) 10 pages even when at end of set (previously might only display set_range()/2 links)

    28/6/1007
    StupidRalph just pointed out that there is the possibility of XSS in the code above & he is quite right.
    I will not however be adding any checks for tainted data in the class above for the following reason.

    There are so many places in a reasonably sized application for tainted data to cause havoc which means that there can be hundreds of bits of code that require tainted data to be escaped or otherwise processed, because of that I now filter all incoming data long before that data gets anywhere near my classes or functions... e.g. any page should..
    initialize (load config vars etc)
    iterate through all potential sources of trouble and clean (GET, POST COOKIE etc)
    then and only then load the logic of your the application and play with data.

    Much code is distributed with built in error/injection checks, this is ok until you realize you may end up doing the same thing to the same data time and time again, also you may not like the authors validation routines and you probably do not want several authors different routines clogging up your code.

    So the moral is, the class above is insecure unless you already employ some pre-filtering of GPC data.
    Last edited by firepages; 06-28-2007 at 02:06 PM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very nice. This could save massive amounts of time in writing pagination code, for my own site. I like how flexible it is in the display of the page links and such, especially how you can easily integrate it into current queries by just modifying the code a bit and making a call to your class. Great job! =)
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is really helpful. I'd reccomend it to anyone

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm I have a problem with this class, which i am looking into but haven't solved yet.(and i want to use it cause it looks funky :-) )
    On using:
    PHP Code:
    $pager->set_range(10); 
    I get the following on first entering the page:
    Code:
    Page 1 of 2
    Displaying results 1 to 3 of 6
    1 &#187; 2 &#187; 3 &#187; 4 &#187; 5 &#187; 6 &#187; 7 &#187; 8 &#187; 9 &#187; 10
    page 1 looks like this:
    Code:
    Page 1 of 2
    Displaying results 1 to 3 of 6
    1 &#187; 2 &#187; 3 &#187; 4 &#187; 5 &#187; 6 &#187; 7 &#187; 8 &#187; 9 &#187; 10

    page 2 looks like this:
    Code:
    Page 2 of 2
    Displaying results 4 to 6 of 6
    0 &#187; 1 &#187; 2
    extra pages all look like this:
    Code:
    Page 3 of 2
    Displaying results 7 to 6 of 6
    0 &#187; 1 &#187; 2

    Plus any chance of adding an option for the following:
    forward/back previous/next or whatever people want to use
    First page/Last page
    my mind is on a permanent tangent

  • #5
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and a nother quick suggested alteration(line 77):
    PHP Code:
    $s = (substr($q01) == '?') ? '&amp;' '?' 
    changing the & to &amp; will satisfy validators, and is safer to use.
    my mind is on a permanent tangent

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,048
    Thanks
    10
    Thanked 93 Times in 91 Posts
    Page 1 of 2
    Displaying results 1 to 3 of 6
    with a range of 10 that should only return 1 page... I can't reproduce this , so I am guessing that the WHERE clause in your counting query is not the same as the WHERE in your actual query ?? , if not could you post your code ?

    Made the &amp; change cheers !
    Added optional 'first' and 'last' replacer arguments to get_range() , you dont have to pass them & if you do they currently only get shown if relevant, need to do some more checking but I can smell lunch
    Last edited by firepages; 01-22-2006 at 04:32 AM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It does this for me too, and it can also go into negative numbers.

    -3 -2 -1 0 1 2 3 (for example).
    "$question = ( to() ) ? be() : ~be();"

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,048
    Thanks
    10
    Thanked 93 Times in 91 Posts
    doh , sorry for casting asparagus ~ twas indeed me.
    class should now work as expected (& yes I spotted the problem if per_page is odd, will fix)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    'First' appear to show on page 1 for me, surely it shouldn't show until page 2 and greater?
    my mind is on a permanent tangent

  • #10
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,048
    Thanks
    10
    Thanked 93 Times in 91 Posts
    cool ,done.
    change this
    $lfirst = (!empty($first)) ? str_replace($this->_l_tpls,array($pre_url.'1',$first),$format) .$sep : '' ;
    to this
    $lfirst = (!empty($first) && $this->curr >1 ) ? str_replace($this->_l_tpls,array($pre_url.'1',$first),$format) .$sep : '' ;
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #11
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent, and many thanks this is the first pagination class I have seen that actually worked how I wanted it to!

    In your example you gave basic instructions for displayin the output, for anyone that is interested I have added in the following:
    PHP Code:
    //after the $max= query
    if(isset($_GET['view']))$records=$max;

    //and then for displaying the pagination:
    echo '<div class="paginate">';
    if(
    $pager->_pages >= 2){
        echo 
    $pager->get_title('Viewing page {CURRENT} of {MAX}<br />Displaying results {FROM} to {TO} of {TOTAL}'). ' <br />';
    }else{
        echo 
    $pager->get_title('Viewing page {CURRENT} of {MAX}'). ' <br />';
    }
    echo 
    $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ','First','Last').'<br />';
    //echo $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ').'<br /><br />';
    if($pager->_pages >= 2){
        echo 
    '<a href="'.$_SERVER['PHP_SELF'].'?view=all">View all</a>';
    }
    echo 
    '</div>'
    Adding in a view all link seemed appropiate to me, though I dare say it could be added to the class?
    my mind is on a permanent tangent

  • #12
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    help, I am trying to get this to work but I am obviously not doing something correct, are there variable in this script that should be changed?

    could someone please explain what needs to be done to make it work?

    thanks.

  • #13
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    we'd need to see your code!
    my mind is on a permanent tangent

  • #14
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, here you go.
    Code:
    <HTML>
    <HEAD>
    <META NAME="description" CONTENT="Find Mens <?php echo $ssrch2;?> <?php echo $ssrch3;?> at NSBSportswear. Peruse an inventory of over 10 million clothing items at low prices. <?php echo $ssrch;?> <?php echo $ssrch2;?> <?php echo $ssrch3;?> now on sale">
    <SCRIPT LANGUAGE="JavaScript">
    var maxAdNo = 3
    var adNo
    var myAd = new Array()
    myAd[0] = '<a href="http://www.shareasale.com/r.cfm?b=36651&u=106368&m=7712&urllink=&afftrack=" target="_new"><img src="http://www.nsbsportswear.com/coolibar1.jpg" border="0"></a>'
    myAd[1] = '<a href="http://www.shareasale.com/r.cfm?b=44437&u=106368&m=7866&urllink=&afftrack=" target="_new"><img src="http://www.nsbsportswear.com/ea1.gif" border="0"></a>'
    myAd[2] = '<a href="http://www.shareasale.com/r.cfm?b=38521&u=106368&m=8112&urllink=&afftrack=" target="_new"><img src="http://www.nsbsportswear.com/wf1.gif" border="0"></a>'
    myAd[3] = '<a href="http://www.shareasale.com/r.cfm?b=43478&u=106368&m=8112&urllink=&afftrack=" target="_new"><img src="http://www.nsbsportswear.com/av1.gif" border="0"></a>'
    </script>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>
    <BODY BGCOLOR="#005D90" LINK="#0000FF" VLINK="#6666FF" ALINK="#0000FF">
    <TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER">
      <TR>
        <TD ROWSPAN="3" BGCOLOR="#005D90" WIDTH="1">&nbsp;</TD>
        <TD ALIGN="LEFT" VALIGN="TOP" WIDTH="50" BGCOLOR="#FFFFFF"><IMG SRC="http://www.nsbsportswear.com/corner2.png" WIDTH="50" HEIGHT="50"></TD>
        <TD ROWSPAN="3" ALIGN="CENTER" VALIGN="MIDDLE"> 
          <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER">
            <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
              <TD COLSPAN="4"> 
                <TABLE WIDTH="650" BORDER="0" CELLSPACING="0" CELLPADDING="0">
                  <TR> 
                    <TD ALIGN="RIGHT" VALIGN="TOP"><IMG SRC="http://www.nsbsportswear.com/d3.png" WIDTH="25" HEIGHT="25"></TD>
                    <TD ROWSPAN="3" ALIGN="CENTER" VALIGN="BOTTOM"><A HREF="http://www.nsbsportswear.com" title="NSB Sportswear Home Page"><IMG SRC="http://www.nsbsportswear.com/smithtop.png" WIDTH="600" HEIGHT="80" BORDER="0"></A></TD>
                    <TD ALIGN="LEFT" VALIGN="TOP"><IMG SRC="http://www.nsbsportswear.com/d4.png" WIDTH="25" HEIGHT="25"></TD>
                  </TR>
                  <TR> 
                    <TD>&nbsp;</TD>
                    <TD>&nbsp;</TD>
                  </TR>
                  <TR> 
                    <TD ALIGN="RIGHT" VALIGN="BOTTOM"><IMG SRC="http://www.nsbsportswear.com/d2.png" WIDTH="25" HEIGHT="25"></TD>
                    <TD ALIGN="LEFT" VALIGN="BOTTOM"><IMG SRC="http://www.nsbsportswear.com/d1.png" WIDTH="25" HEIGHT="25"></TD>
                  </TR>
                </TABLE>
              </TD>
            </TR>
            <TR BGCOLOR="#005D90" VALIGN="MIDDLE"> 
              <TD ALIGN="LEFT" COLSPAN="4"> 
                <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="5" ALIGN="CENTER">
                  <TR BGCOLOR="#005D90"> 
                    <TD> 
                      <TABLE WIDTH="98%" BORDER="2" CELLSPACING="0" CELLPADDING="5" ALIGN="CENTER">
                        <TR BGCOLOR="#FFFFFF"> 
                          <TD ALIGN="LEFT" VALIGN="TOP" WIDTH="100"><B><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">All 
                            Men's Categories:</FONT></B><br>
    
    <?php 
    						@include('/home/nsbsports/public_html/scripts/pager.php');
    if (main)   // perform search only if a string was entered. 
       { 
        mysql_connect("localhost", "root", "pwd") or die ("Problem connecting to DataBase"); 
        $srch="%".Man."%"; 
        $query = "select * from categorylinks WHERE gender LIKE '$srch'"; 
        $result = mysql_db_query("nsbsportswear_nav", $query); 
        $num_rows = mysql_num_rows($result);   
        if  ($result) 
        { 
         echo "<table width=100% align=left cellspacing=0 cellpadding=1 border=0><tr> 
            <td align=left WIDTH='100%' Height='0'></td> 
             </tr>"; 
            while ($r = mysql_fetch_array($result)) {     // Begin while 
                $linktext = $r["display"]; 
                $linkcode = $r["url"];
                $linkdesc = $r["title"];
                $linkgen = $r["gender"];
                $linkcat = $r["category"];
                $linkcategory = $r["linkcategory"];
                     echo "<tr><td align=left><a href='$linkcode' title='$linkdesc'><font size=-1 face-tahoma>$linkcat</font></a></td></tr>"; 
            }                  // end while 
            echo "</table>\n"; 
         } else { echo "problems...."; } 
       } else { 
       echo "Search string is empty. <br> Go back and type a string to search"; 
       }
    ?>
    
                          </TD>
                          <TD ALIGN="LEFT" VALIGN="TOP"><? 
     /* Set current, prev and next page */ 
    $page = (!isset($_GET['page']))? 1 : $_GET['page'];  
    $prev = ($page - 1); 
    $next = ($page + 1); 
    $ppages = ($page - 4);  // setup for previous 4 pages
    if($page < '4') { $ppages = "";}
    $npages = ($page + 9);  // setup for next 5 pages
    $ssrch="12345";
    $ssrch2 ="shirt";
    $ssrch3 ="";
    $_SESSION['srch'] = $ssrch;
    $_SESSION['srch2'] = $ssrch2;
    $_SESSION['srch3'] = $ssrch3;
    $_SESSION['lookup']=$lookup;
    $_SESSION['disnum']=$disnum;
    $srch = $_SESSION['srch'];
    $srch2 = $_SESSION['srch2'];
    $srch3 = $_SESSION['srch3'];
     // Set current, prev and next page  
    $prev = ($page - 1); 
    $next = ($page + 1); 
    $_SESSION['prev']=$prev;
    $_SESSION['next']=$next;
    /* Max results per page */ 
    $max_results = '20'; /* Calculate the offset */ 
    
    $from = (($page * $max_results) - $max_results); 
    //$from=$_SESSION['from'];
    $dbh=MySQL_connect ("localhost", "root", "pwd")
           or die ('I cannot connect to the database because: ' . mysql_error());
              mysql_select_db ("apparrell");
        $query = "select * from stuff WHERE searchdata LIKE ('% $srch %') AND searchdata LIKE ('% $srch2 %')AND searchdata LIKE ('% $srch3 %')";
    	$result = mysql_query($query); 
    	$total_results = mysql_num_rows($result); 
    	$total_pages = ceil($total_results / $max_results); 
    	
    	    echo "<p align=center><div align=center><H1>Mens $ssrch2 $ssrch3</H1>";
    	
    #
    #
    #
    #
    #
    #
    // start of new pagination script
    $max = $total_pages;
    $pager = new pager( 
        $max ,                     /*see above*/
        20,                         /*how many records to display at one time*/
        @$_GET['_p']  /*this is the current page no carried via _GET*/
        ) ;
    	$pager->set_range();
    // end of new pagination script
    
    
    
    #
    #
    //and then for displaying the pagination: 
    #
    #
    echo '<div class="paginate">'; 
    if($pager->_pages >= 2){ 
        echo $pager->get_title('Viewing page {CURRENT} of {MAX}<br />Displaying results {FROM} to {TO} of {TOTAL}'). ' <br />'; 
    }else{ 
        echo $pager->get_title('Viewing page {CURRENT} of {MAX}'). ' <br />'; 
    } 
    echo $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ','First','Last').'<br />'; 
    echo $pager->get_range('<a href="{LINK_HREF}">{LINK_LINK}</a>',' &raquo ').'<br />'; 
    if($pager->_pages >= 2){ 
     } 
    echo '</div>';  
    // end of new pagination script echo
    #
    #
    #
    #
    #
    #
    #  start of 2nd query and display the results 
    #
    #
    #
    	  if($page==1){$from='0';}
    	 $query="select * from stuff WHERE searchdata LIKE ('% $srch %') AND searchdata LIKE ('% $srch2 %') AND searchdata LIKE ('% $srch3 %')  ORDER BY NAME ASC LIMIT $from, $max_results";
    	 	$result = mysql_query($query);
    		$rows=mysql_num_rows($result);
            echo "</div>";
    	//Generates the list of chapters 
    	 echo "<br><table width=100% align=center cellspacing=0 cellpadding=8 bordercolor=#005D90 border=0><tr>";
    		while($data1 = mysql_fetch_array($result)) {  
     		 extract($data1,EXTR_OVERWRITE);
           echo "<td align=center bgcolor=#005D90 WIDTH='50%' Height='5'></td> 
            <td align=center bgcolor=#005D90 WIDTH='50%' Height='5'></td>
            </tr>"; 
                // Begin while 
                $Item = $data1["NAME"]; 
                $Site_Link = $data1["BUYURL"];
                $Buy_Site = $data1["PROGRAMNAME"];
                $Buy_Link = $data1["BUYURL"]; 
                $Price = $data1["PRICE"];
                $Cat_two = $data1["ADVERTISERCATEGORY"];
                $Imp_Link = $data1["IMPRESSIONURL"];
                $Image_Link = $data1["IMAGEURL"];    
                $Desc = $data1["DESCRIPTION"];
                $botbrand = $data1["MANUFACTURER"];
                $boturl = $data1["BUYURL"];
                $uid = $data1["uid"];
                $Button_Link = $data1["BUYURL"];   
    			// add these to your scripts to indicate sales price, savings, and % saved
    			$sale_price = $data1["SALEPRICE"];
    			$psave = $data1["PSAVE"];
    			$dsave = $data1["DSAVE"];   
                      echo "<tr>                      
                            <td align=left><font face=tahoma size=3><b>$Item</b></font><br><font face	 						=arial size=2>$Desc<br><br>Outlet Priced: $ $Price";
    						if($dsave > '0.00'){echo "<br><TABLE WIDTH='100%' BORDER='1' CELLSPACING='0' CELLPADDING='5' ALIGN='CENTER' BORDERCOLOR='#005D90' BORDERCOLORLIGHT='#005D90' BORDERCOLORDARK='#005D90'>
            <TR ALIGN='CENTER' VALIGN='MIDDLE'> 
              <TD ALIGN='LEFT' BGCOLOR='#005D90'><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='#FF0000'><B><FONT COLOR='#FFFFFF'>On 
                Sale!</FONT></B></FONT></TD>
              <TD BGCOLOR='#005D90' ALIGN='LEFT'><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='#FFFFFF'><B>$$SALEPRICE</B></FONT></TD>
            </TR>
            <TR ALIGN='CENTER' VALIGN='MIDDLE'> 
              <TD ALIGN='LEFT'><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2'><B><FONT COLOR='#005D90'>You 
                Save!</FONT></B></FONT></TD>
              <TD ALIGN='LEFT'><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='#005D90'><B>$$dsave</B></FONT></TD>
            </TR>
            <TR ALIGN='CENTER' VALIGN='MIDDLE'> 
              <TD><img src='http://nsbsportswear.com/smile.jpg' BORDER='0'></TD>
              <TD BGCOLOR='#005D90' ALIGN='LEFT'><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2'><B><FONT COLOR='#FFFFFF'>That's<BR>
                $psave%</FONT></B></FONT></TD>
            </TR>
          </TABLE>";}
    				echo"<br>Offered by: <a href='$Site_Link&afsrc=1' target='_new'>$Buy_Site
    						</a></td>";
    					echo	"<td align=center><img src='$Image_Link' alt='$Item, offered by $Buy_Site, $ $Price'><br>";echo"<br><a href='$Site_Link&afsrc=1' target='_new'><img src='http://www.nsbsportswear.com/images/ss.jpg' border='0'></a></td></tr>";  }          // end while 
    		echo "</table>\n"; 		 
        echo "<div align=center>";    
    echo "</div>";
       ?><br><div align="center"><SCRIPT TYPE="text/javascript"><!--
    google_ad_client = "pub-3062514307296645";
    google_ad_width = 336;
    google_ad_height = 280;
    google_ad_format = "336x280_as";
    google_ad_type = "text";
    google_ad_channel ="5909127837";
    google_color_border = "005D90";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "0000FF";
    google_color_text = "000000";
    //--></SCRIPT>
    <SCRIPT TYPE="text/javascript"
      SRC="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </SCRIPT></div></TD>
                          <TITLE>NSB Sportswear Outlet - Mens <?php echo $ssrch2;?> <?php echo $ssrch3;?></TITLE>
                          <TD ALIGN="LEFT" VALIGN="TOP" WIDTH="120"> 
                            <TABLE WIDTH="100%" BORDER="2" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#005D90" BORDERCOLOR="#005D90" ALIGN="CENTER">
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/men/index.html"><IMG SRC="http://www.nsbsportswear.com/images/men.jpg" WIDTH="100" HEIGHT="18" BORDER="0" ALT="Men's Sportswear"></A></TD>
                              </TR>
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/women/index.html"><IMG SRC="http://www.nsbsportswear.com/images/women.jpg" WIDTH="100" HEIGHT="18" BORDER="0" ALT="Women's Sportswear"></A></TD>
                              </TR>
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/kids/index.html"><IMG SRC="http://www.nsbsportswear.com/images/kids.jpg" WIDTH="100" HEIGHT="18" BORDER="0" ALT="Kids Sportswear"></A></TD>
                              </TR>
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/coupons.htm" TARGET="_blank"><IMG SRC="http://www.nsbsportswear.com/images/coupons.jpg" WIDTH="100" HEIGHT="18" BORDER="0" ALT="Get Coupons"></A></TD>
                              </TR>
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/search.htm" TARGET="_blank"><IMG SRC="http://www.nsbsportswear.com/images/searchb.jpg" WIDTH="100" HEIGHT="18" BORDER="0"></A></TD>
                              </TR>
                              <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
                                <TD><A HREF="http://www.nsbsportswear.com/brand/index.html"><IMG SRC="http://www.nsbsportswear.com/images/brand.jpg" WIDTH="100" HEIGHT="50" BORDER="0"></A></TD>
                              </TR>
                            </TABLE>
                            <BR><SCRIPT LANGUAGE="JavaScript">
    adNo = Math.round(Math.random() * maxAdNo)
    document.write(myAd[adNo])
    </SCRIPT><br><br>
                          </TD>
                        </TR>
                      </TABLE>
                    </TD>
                  </TR>
                </TABLE>
              </TD>
            </TR>
            <TR ALIGN="CENTER" VALIGN="MIDDLE" BGCOLOR="#FFFFFF"> 
              <TD COLSPAN="4"> 
                <TABLE WIDTH="650" BORDER="0" CELLSPACING="0" CELLPADDING="0">
                  <TR> 
                    <TD ALIGN="RIGHT" VALIGN="TOP"><IMG SRC="http://www.nsbsportswear.com/d3.png" WIDTH="25" HEIGHT="25"></TD>
                    <TD ROWSPAN="3" ALIGN="CENTER" VALIGN="BOTTOM"><A HREF="http://www.nsbsportswear.com" title="NSB Sportswear Home Page"><IMG SRC="http://www.nsbsportswear.com/smithtop.png" WIDTH="600" HEIGHT="80" BORDER="0"></A></TD>
                    <TD ALIGN="LEFT" VALIGN="TOP"><IMG SRC="http://www.nsbsportswear.com/d4.png" WIDTH="25" HEIGHT="25"></TD>
                  </TR>
                  <TR> 
                    <TD>&nbsp;</TD>
                    <TD>&nbsp;</TD>
                  </TR>
                  <TR> 
                    <TD ALIGN="RIGHT" VALIGN="BOTTOM"><IMG SRC="http://www.nsbsportswear.com/d2.png" WIDTH="25" HEIGHT="25"></TD>
                    <TD ALIGN="LEFT" VALIGN="BOTTOM"><IMG SRC="http://www.nsbsportswear.com/d1.png" WIDTH="25" HEIGHT="25"></TD>
                  </TR>
                </TABLE>
              </TD>
            </TR>
          </TABLE>
        </TD>
        <TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="50" BGCOLOR="#FFFFFF"><IMG SRC="http://www.nsbsportswear.com/corner.png" WIDTH="50" HEIGHT="50"></TD>
      </TR>
      <TR> 
        <TD BGCOLOR="#FFFFFF">&nbsp;</TD>
        <TD BGCOLOR="#FFFFFF">&nbsp;</TD>
      </TR>
      <TR> 
        <TD ALIGN="LEFT" VALIGN="BOTTOM" BGCOLOR="#FFFFFF"><IMG SRC="http://www.nsbsportswear.com/corner3.png" WIDTH="50" HEIGHT="50"></TD>
    
        <TD ALIGN="RIGHT" VALIGN="BOTTOM" BGCOLOR="#FFFFFF"><IMG SRC="http://www.nsbsportswear.com/corner4.png" WIDTH="50" HEIGHT="50"></TD>
      </TR>
    </TABLE>
    </BODY>
    </HTML>
    and I just copied the code from above.

    thanks.

  • #15
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll be honest, your code is a little bit difficult to go through.

    You appear to have another form of pagination in there as well, that certainly won't help.

    I also cannot find the equivalent to this:
    PHP Code:
    $max mysql_resultmysql_query("SELECT COUNT(id) FROM table WHERE id > 0"), ) ; 
    But I may have missed it.

    similarily:
    PHP Code:
    $q mysql_query("SELECT id,name FROM table WHERE id > 0 LIMIT ".$pager->get_limit()); 
    As such this leads me to believe that other portions may be missing as well.

    Rather than code it for you, can i suggest you copy your code, strip out all the unnecessary bits, and rebuild from there. (even remove all the tables, have a bare bones mysql connection/pull results/pagination/display results). From there you would be able to work backwards to integrate it into your existing page. By doing it this way you'll learn how the thing works as you go along.

    Hope that helps.

    Others may of course be able to help straight away :-)
    my mind is on a permanent tangent


  •  
    Page 1 of 5 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •