Pagination
-
Hi I have the following code : I am trying to paginated my table, I have got it to paginated but the next link takes me to the home page.
Could someone please assist me.Thanks
Gwen
[ Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser. Or use pastebin.com instead. ]
<?php global $wpdb; $numpostss = $wpdb->get_results("SELECT COUNT(*) FROM hotels WHERE cat='hotel'", ARRAY_N); $numposts = $numpostss[0][0]; $postsperpage = 3; $numofpages = intval($numposts/$postsperpage); if ($numposts%$postsperpage) { $numofpages=$numofpages+1; }; $lastpageposts = $numposts-(($numofpages-1)*$postsperpage); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $offset = ($paged-1) * $postsperpage; if ($paged==$numpofages) { $postsperpage=$lastpageposts; } $myrows = $wpdb->get_results( "SELECT * FROM hotels WHERE cat='hotel' LIMIT $offset, $postsperpage", OBJECT); //print_r($myrows); if ($myrows) { foreach ( $myrows as $hotel ) { echo "<table width='100%' align='center' border='3px solid grey'>"; echo"<tr>"; echo"<th>Picture</th>"; echo "<th>Details</th>"; echo "<th>More Info</th>"; echo "</tr>"; echo "<tbody>"; echo "<tr>"; echo "<td><img src='/images/$hotel->pic' alt='$hotel->name'/></td>"; echo "<td><h1>{$hotel->name }</h1><h3>{$hotel->address}</h3><p class=\"tag\">{$hotel->tag} <a href="info.php?id=$hotel-">id'>More Info </a></p></td>"; echo "<td class='contactd'><p class=\"price\"> From £$hotel->Price </p> Per Person Per Night<p class=\"price\">Contact Them On</p>{$hotel->contact}<p class=\"price\">Visit their Website </p><a>website'>{$hotel->website}</a></td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; } } ?> <?php $precpage=$paged-1; $nextpage=$paged+1; if ($paged>1) { if ($precpage==1) { echo ('<a href="../../">? Home</a>'); } else { echo ('<a href="../' . $precpage . '/">? Preceding Page</a> ? <a href="../../">Home</a>'); } } if ($nextpage<=$numofpages) { if ($paged==1) { echo ('<a href="./page/'); } else { echo (' ? <a href="../'); } echo ($nextpage . '/">Next Page ?'); } ?> </div>
- The topic ‘Pagination’ is closed to new replies.