Jump to content

Limit results per page


Dada78

Recommended Posts

Ok I guess I should have asked this in the other thread but I think we will let that one fade off since this is a different problem. On this page below:

 

http://mesquitechristmas.com/local/browse.php

 

It will list all the displays that are in the DB. How can I limit the number it shows per page say 10 then create a new page to go to then show 10 more etc? Is their a post of how to I can read on this maybe?

 

 

Here is the code for that page.

 

<?php
include ('db_connect.php');
function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {
      $sql = "SELECT * FROM users";
      if($result = mysql_query($sql)) {
        $i = 0;
         while ($row = mysql_fetch_array ($result)) {
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr>
                    <td bgcolor='".$color."' style='border-top: 1px solid #336633' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td bgcolor='".$color."' style='border-top: 1px solid #336633'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td bgcolor='".$color."' style='vertical-align: middle; border-top: 1px solid #336633'>> 
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> 
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>"; 
              ++$i;
         }
      }
   }
}

?> 

 

-Thanks

 

 

Link to comment
Share on other sites

you can use the simple pagination script:

select * from table limit(x,y)

x = the row you want to start your query with (ex. if you want 5 rows per page, then x would have to be 6 on the 2nd page, 11 on the 3rd, etc)

 

y = the no. of rows per page (ex. if you want 5 rows per page, then y would be 5)

Link to comment
Share on other sites

I have tried the tutorial and I get this error.

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table LIMIT 0, 25' at line 1

 

Not sure where to go from here. Here is the code I am working with.

 

<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

      $limit      = 25;

      $query_count    = "SELECT count(*) FROM table";
      if(empty($page)){ 
       $page = 1;
   } 
      $limitvalue = $page * $limit - ($limit);

      $query  = "SELECT * FROM table LIMIT $limitvalue, $limit";        
      $result = mysql_query($query) or die("Error: " . mysql_error());
         if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!"); }                               
{
        $i = 0;
         while ($row = mysql_fetch_array ($result)) {
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>> 
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> 
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>"; 
              ++$i;

if($page != 1){ 
        $pageprev = $page--;
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit; 
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
    
    mysql_free_result($result); 

         }
      }
   }
}

?> 

 

-Thanks

 

 

Link to comment
Share on other sites

I have tried the tutorial and I get this error.

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table LIMIT 0, 25' at line 1

 

Not sure where to go from here. Here is the code I am working with.

 

<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

      $limit      = 25;

      $query_count    = "SELECT count(*) FROM table";
      if(empty($page)){ 
       $page = 1;
   } 
      $limitvalue = $page * $limit - ($limit);

      $query  = "SELECT * FROM table LIMIT $limitvalue, $limit";        
      $result = mysql_query($query) or die("Error: " . mysql_error());
         if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!"); }                               
{
        $i = 0;
         while ($row = mysql_fetch_array ($result)) {
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>> 
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> 
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>"; 
              ++$i;

if($page != 1){ 
        $pageprev = $page--;
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit; 
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
    
    mysql_free_result($result); 

         }
      }
   }
}

?> 

 

-Thanks

 

 

you didnt put a parenthesis between the limit inputs.

 

select * from table limit(x,y);

Link to comment
Share on other sites

I did that and now I get this error

 

Parse error: syntax error, unexpected T_VARIABLE in /home/mesquit1/public_html/local/browse.php on line 24

 

I added parenthesis as suggested

 

$query  = "SELECT * FROM table LIMIT "$limitvalue", "$limit"";

 

Of did you mean like this.

 

$query  = "SELECT * FROM table LIMIT ($limitvalue", "$limit)";

 

 

That gives me the previous error.

Link to comment
Share on other sites

OK look at this page it show the error and it only returns one result

 

http://mesquitechristmas.com/local/browse.php

 

Here is the code I am using now.

 

<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

      $limit      = 10;

      $query_count    = "SELECT count(*) FROM table";
      if(empty($page)){ 
       $page = 1;
   } 
      $limitvalue = $page * $limit - ($limit);

      $query  = "SELECT * FROM users LIMIT $limitvalue, $limit";        
      $result = mysql_query($query) or die("Error: " . mysql_error());
         if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!"); }                               
{
        $i = 0;
         while ($row = mysql_fetch_array ($result)) {
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>> 
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> 
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>"; 
              ++$i;

if($page != 1){ 
        $pageprev = $page--;
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit; 
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
    
    mysql_free_result($result); 

         }
      }
   }
}

?> 

Link to comment
Share on other sites

I did that and now I get this error

 

Parse error: syntax error, unexpected T_VARIABLE in /home/mesquit1/public_html/local/browse.php on line 24

 

I added parenthesis as suggested

 

$query  = "SELECT * FROM table LIMIT "$limitvalue", "$limit"";

<-- no parenthesis

 

Of did you mean like this.

 

$query  = "SELECT * FROM table LIMIT ($limitvalue", "$limit)";

<-- wrong quotations

 

 

That gives me the previous error.

 

do it like this:

$query  = "SELECT * FROM table LIMIT (".$limitvalue.", ".$limit.")";

or

$query  = "SELECT * FROM table LIMIT ({$limitvalue}, {$limit})";

Link to comment
Share on other sites

The suggestion above produces this error.

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(0, 10)' at line 1

 

 

So I am using the following code but you can see what it is doing and the error. It only produces one entry when their are suppose to be 4.

 

http://www.mesquitechristmas.com/local/browse.php

 

<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

      $limit          = 10;               
    $query_count    = "SELECT count(*) FROM users";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count); 

    if(empty($page)){
        $page = 1;
    }
        

    $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT * FROM users LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    } 
{
        $i = 0;
      while ($row = mysql_fetch_array ($result)){
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>>
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>>
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>";
              ++$i;

if($page != 1){
        $pageprev = $page--;

        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;

        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }

    mysql_free_result($result);

         }
      }
   }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Mesquite Texas Country Christmas" />
<meta name="keywords" content="Mesquite, Texas, Country Christmas" />
<meta name="author" content="NA" />
<link rel="stylesheet" type="text/css" href="/stylesheet.css" media="screen" title="FBC" />
<script type="text/javascript" src="drop_down.js"></script>
<title>A Mesquite Country Christmas</title>
</head>
<body>

<div id="wrap">

<a href="/index.html">
<img id="frontphoto" src="/images/header.png" width="760" height="237" alt="Mesquite Country Christmas" border="0"></a>

<div id="menu">

<h2 class="hide">Menu:</h2>

<ul id="avmenu">
<li><a href="/index.html">Home</a></li>
<li><a href="/christmasstory.html">The Christmas Story</a></li>
<li><a href="/directions.html">Directions</a></li>
<li><a href="#">Information</a><ul>
      <li><a href="/information.html">Display Facts & Info</a></li>
      <li><a href="/faq.html">FAQ</a></li>
      <li><a href="/playlist.html">2008 Playlist</a></li>
      <li><a href="#">Christmas History</a></li>
  </ul></li>
<li><a href="#">Photos</a>
  <ul>
      <li><a href="/2007photos.html">2007</a></li>
  </ul></li>
<li><a href="#">Videos</a>
  <ul>
      <li><a href="/2007videos.html">2007</a></li>
  </ul></li>
<li><a href="/guestbook.php">Guestbook</a></li>
<li><a href="/webcam.html">Web Cam</a></li>
<li><a href="/webradio.html">Internet Radio</a></li>
<li><a href="http://www.noradsanta.org/" TARGET="_blank">Track Santa</a></li>
<li><a href="/projects.html">Projects & How Tos</a></li>
<li><a href="/links.html">Links</a></li>
<li><a href="/contact_us.html">Contact Us</a></li>
</ul>

<center><a href="http://www.toysfortots.org/" TARGET="_blank"><img src="/images/toys_for_tots.jpg" border="0" width="110" height="153" vspace="10"></a></center>

<center><a href="http://christmas.bronners.com/2007/house/534.html"><img src="http://christmas.bronners.com/voteforme/vote.jpg" border="0" width="110" height="153" alt="christmas decorations" vspace="10"></a></center>

</div>

<div id="content">

<div class="fadebox">

<h2>Mesquite Christmas Display Finder</h2>

<hr />

<p> Do you drive around aimlessly looking for Christmas lights every year? We are here to help make that tradition better by allowing you to search for local displays in Mesquite and get directions to them. And if you have a display of your own, you can add it to our database for others to find and enjoy!</p>

<p><span class="title">Current Displays In Mesquite</span><br /><table border=0 cellspacing=0 cellpadding=4 width=100% style='border-bottom: 1px solid #336633'><?php show_data(); ?></table> </p>

</div>



   </div>
</div>

<div id="footer">
© 2007 Mesquite Country Christmas

<br />
<br />

<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//468x60, created 1/8/08
google_ad_slot = "0360766123";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


</div>

</div>
</body>
</html>

 

-Thanks

 

 

Link to comment
Share on other sites

Ok I have been working on this and I am making progress. I just need a small tweaking and I am stuck as where to look. The top shows a bunch or next 1 prev across the top where it should only be one and I would like it at the bottom right instead of the top. Also each row is suppose to be alternating colors which worked before I added the pagination to the code. Here can see what it is doing from the link below.

 

http://mesquitechristmas.com/local/browse.php

 

Here is the code I am working with

 

<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

    $limit          = 10;
    $query_count    = "SELECT count(*) FROM users";
    $result_count   = mysql_query($query_count);
    $totalrows      = mysql_num_rows($result_count);

    if(empty($page)){
        $page = 1;
    }

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM users LIMIT $limitvalue, $limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }
{
        $i = 0;
      while ($row = mysql_fetch_array ($result)){
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>>
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>>
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>";
              ++$i;
if($page != 1){
        $pageprev = $page--;

        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;

        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }

         }
            mysql_free_result($result);
      }
   }
}?>

 

-Thanks

 

 

Link to comment
Share on other sites

That didn't work but I don't see any difference between the two code besides the single quotes around the  table

 

Any other ideas or suggestions.

 

One thing I notice is at the top of the page where it shows

 

PREV10 1 NEXT10

 

Their are 4 of them, one for each entry. I realized this when I deleted two entries, two of them went away. I am not sure what is cause that but if someone can help me find that it might fix the problem I am having.

 

-Thanks

Link to comment
Share on other sites

Same problem, different day. Any help on this would be greatly appreciative. I have been working on this and I am making progress. I just need a small tweaking and I am stuck as where to look. The top shows a bunch or next 1 prev across the top where it should only be one and I would like it at the bottom right instead of the top. Also each row is suppose to be alternating colors which worked before I added the pagination to the code. Here can see what it is doing from the link below.


Here is the link which you can see the problem that is occurring that I stated above.

http://mesquitechristmas.com/local/browse.php

Here is the code I am working with


[code=php:0]<?php
include ('db_connect.php');

function show_data(){
   $id = array();
   $imgurl = array();
   $address = array();
   $city = array();
   $state = array();
   $postal = array();
   $country = array();
   $id = mysql_real_escape_string($_GET['id']);
   $i=0;
   if(isset($id)) {

    $limit          = 10;
    $query_count    = "SELECT count(*) FROM users";
    $result_count   = mysql_query($query_count);
    $totalrows      = mysql_num_rows($result_count);

    if(empty($page)){
        $page = 1;
    }

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM users LIMIT $limitvalue, $limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }
{
        $i = 0;
      while ($row = mysql_fetch_array ($result)){
            $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
            $id[$i] = $row["id"];
            $imgurl[$i] = $row["imgurl"];
            $address[$i] = $row["address"];
            $city[$i] = $row["city"];
            $state[$i] = $row["state"];
            $postal[$i] = $row["postal"];
            $country[$i] = $row["country"];

            print"<tr bgcolor='".$color."'>
                    <td class='bg3' width=110>
                      <a href='/local/display.php?id= $id[$i]'>
                        <img src='$imgurl[$i]' class='border' height'75' width='100'>
                      </a>
                    </td>
                    <td class='bg3'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td>
                    <td class='bg3' style='vertical-align: middle'>>
                      <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>>
                      <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'>
                      <b>Get Directions</b>
                      </a>
                   </td>
            </tr>";
              ++$i;
if($page != 1){
        $pageprev = $page--;

        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;

        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }

         }
            mysql_free_result($result);
      }
   }
}?>

 

 

-Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.