Announcement

Collapse
No announcement yet.

MySQL results on multiple pages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jrwap
    replied
    Max Albert

    The first link was very helpful... the code just needed a little tinkering and it works perfectly for me.

    Thank you very much!!!

    -JRW

    Leave a comment:


  • jrwap
    replied
    Well, thanks for the links... I'll be sure to check them out. I did search using a bunch of different terms and didnt come up with those links.

    Thanks again,

    -JRW

    Leave a comment:


  • Mark Hensler
    replied
    http://www.vbulletin.com/forum/showt...threadid=37641
    http://www.vbulletin.com/forum/showt...threadid=37620

    Leave a comment:


  • jrwap
    started a topic MySQL results on multiple pages

    MySQL results on multiple pages

    I am trying to get some results to show up on multiple pages, but its not working...

    PHP Code:
     <?php
    require("./global.php");

    eval(
    "\$header = \"".gettemplate("header",1,0)."\";");;
    eval(
    "\$footer = \"".gettemplate("footer",1,0)."\";");

      if (
    $manufacturer_id) {
        
    $manufacturer $DB_site->query_first("SELECT name, logo, website, salesemail, techemail, usaddress, city, state, zipcode, phonenumber FROM manufacturers WHERE manufacturer_id = '$manufacturer_id'");
        
    extract($manufacturer);
        
        
    $color '{firstaltcolor}';
        eval(
    "\$manufacturerbits .= \"".gettemplate("manufacturerbits",1,0)."\";");
      } else {
          
    $manufacturers $DB_site->query("SELECT manufacturer_id, name, website FROM manufacturers ORDER BY name ASC");
          if (!
    $DB_site->num_rows($manufacturers)) {
            print eval(
    "\$manufacturerbits .= \"".gettemplate("manufacturer_error",1,0)."\";");
          } else {

        
    $limit=20// rows to return
        
    $numresults=DB_site->query("select * from manufacturers ORDER BY name ASC");
        
    $numrows=mysql_num_rows($numresults);

        
    // next determine if offset has been passed to script, if not use 0
    if (empty($offset)) {
        
    $offset=1;
    }

    // get results
    $result=$DB_site->query("SELECT manufacturer_id, name,website FROM manufacturers ORDER BY name ASC LIMIT $offset,$limit");

    // now you can display the results returned
    while ($data=mysql_fetch_array($result)) {
        
    // include code to display results as you see fit
          
    extract($data);
              
    $color = ($num++ % 2) ? '#DFDFDF' '#F1F1F1';
              eval(
    "\$manufacturerbits .= \"".gettemplate("manufacturerbit",1,0)."\";");  
    }

    // next we need to do the links to other results

    if ($offset==1) { // bypass PREV link if offset is 0
        
    $prevoffset=$offset-20;
        
    $prev "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> &nbsp; \n";
    }

    // calculate number of pages needing links
    $pages=intval($numrows/$limit);

    // $pages now contains int of pages needed unless there is a remainder from division
    if ($numrows%$limit) {
        
    // has remainder so add one page
        
    $pages++;
    }

    for (
    $i=1;$i<=$pages;$i++) { // loop thru
        
    $newoffset=$limit*($i-1);
        eval(
    "\$number .= \"".gettemplate("number",1,0)."\";");  
    }
    }

    // check to see if last page
    if (!(($offset/$limit)==$pages) && $pages!=1) {
        
    // not last page so give NEXT link
        
    $newoffset=$offset+$limit;
        
    $next "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
    }

          }
      }

    eval(
    "dooutput(\"".gettemplate("manufacturer")."\");");
    ?>
    What am I missing here..... I want it to look like:

    [Prev] 1 2 3 [NEXT]

    Thanks,

    -JRW

Related Topics

Collapse

Working...
X