Jump to content

Paging help


pgabriel

Recommended Posts

Hello,

 

I have written some functions that return results from mysql db. I wish to have a pagination sistem and i don`t know how to make it. I will need a little help. Thanks in advance.

 

Query:

function get_cat()
{
   $conn = db_connect();
   $query = 'select catid, catname
             from categories'; 
   $result = @$conn->query($query);
   if (!$result)
     return false;
   $num_cats = @$result->num_rows;
   if ($num_cats ==0)
      return false;  
   $result = db_result_to_array($result);
   return $result; 
}

function get_cat_name($catid)
{
   $conn = db_connect();
   $query = "select catname
             from categories 
             where catid = $catid"; 
   $result = @$conn->query($query);
   if (!$result)
     return false;
   $num_cats = @$result->num_rows;
   if ($num_cats ==0)
      return false;  
   $row = $result->fetch_object();
   return $row->catname; 
}

function get_homes($catid)
{
   if (!$catid || $catid=='')
     return false;
   
   $conn = db_connect();
   $query = "select * from homes where catid='$catid' and type='Offer'";
   $result = @$conn->query($query);
   if (!$result)
     return false;
   $num_homes = @$result->num_rows;
   if ($num_homes ==0)
      return false;
   $result = db_result_to_array($result);
   return $result;
}

 

The display function:

function display_homes_offers($homes_offers_array)
{
  if (!is_array($homes_offers_array))
  {
     echo '<br />No homes in this category.<br />';
  }
  else
  {
    echo '<br /><table width="900" border="1" align="center">';
      
    foreach ($homes_offers_array as $row)
    {
      $url = 'show.php?locID='.($row['locID']);
      echo '<tr><td>';
      if (@file_exists('images/'.$row['locID'].'.jpg'))
      {
        $title = '<img src=\'images/'.($row['locID']).'.jpg\' border=0 />';
        echo '<a href="'.$basehref.'/'.$url.'">'.$title.'</a>';
      }
      else
      {
        echo '<center>Image N/A</center>';
      }
      echo '</td><td width="700">';
  $row['catid'];
  $catname = str_replace("1","Apartaments",$row['catid']);
      $title =  $catname.' de inchiriat in '.$row['judet'];
      echo '<a href="'.$url.'">'.$title.'</a>';
      echo '</td></tr>';
    }
    echo '</table>';
  }
}

 

And the final output:

  $catid = $_GET['catid'];
  $name = get_cat_name($catid);

  // Output -> Offers
  $homes_offers_array = get_homes($catid);
  display_homes_offers($homes_offers_array);

 

How could i make a paging system with this codes?

I have to mention that here is just a part of my code.

I have putted here what makes sense with the Home Offers listing.

 

Thanks!

Gabriel

Link to comment
https://forums.phpfreaks.com/topic/53211-paging-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.