pgabriel Posted May 27, 2007 Share Posted May 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 Here is a post I made a while back with the code you would need to do a pagination. http://www.phpfreaks.com/forums/index.php/topic,140128.0.html You will have to look over it and adapt it to yours. Quote Link to comment Share on other sites More sharing options...
pgabriel Posted May 27, 2007 Author Share Posted May 27, 2007 Thanks for your reply chronister. I will try to implement in mine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.