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