WordPress.org

Ready to get started?Download WordPress

Forums

$wpdb custom table pagination (6 posts)

  1. redds013
    Member
    Posted 1 year ago #

    Good Morning,

    I wondering if someone can help. I want to paginated my results from a custom table in wordpress.

    This is my query. I want to be able to limit the number of hotels on a page and then paginate it to the next page.

    global $wpdb;
    $myrows = $wpdb->get_results( "SELECT * FROM hotels WHERE cat='hotel'", OBJECT);
    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} id'>
    More Info
    </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>website'>{$hotel->website}</td>";
    echo "</tr>";
    echo "</tbody>";

    echo "</table>";

    I would appreciate it if someone could help or point to a tutorial or plugin.

    Thanks

  2. vtxyzzy
    Member
    Posted 1 year ago #

    The WordPress function paginate_links() can be used to paginate an array.

    Also, here is an article that may help: http://wordpress.mcdspot.com/2010/11/25/pagination-using-paginate_links/

  3. redds013
    Member
    Posted 1 year ago #

    Thanks, I have had a look but I am not sure where I need to put in the code,
    When I use the http://wordpress.mcdspot.com/2010/11/25/pagination-using-paginate_links/ way my data dissappears.

    I am really new to php and am really stuck on this one.

    Thanks

  4. vtxyzzy
    Member
    Posted 1 year ago #

    Basically, start with the code from my article on top. You may need to take out the opening <?php tag. Then replace the query in my code with your own leaving the variable as $rows instead of $myrows (for convenience).

    Then in the for loop at the bottom, set it up like this:

    for ($i=$start;$i < $end ;++$i ) {
       $hotel = $rows[$i];
       // Put your table here to display the data.
    }
  5. redds013
    Member
    Posted 1 year ago #

    Wow !!, Thank you very much, I really appreciate it, It works perfectly....
    I can now move on to the next step...
    Thanks Again.

  6. vtxyzzy
    Member
    Posted 1 year ago #

    If your problem has been solved, please use the dropdown on the right to mark this topic 'Resolved' so that anyone else with this question can see that there is a solution.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.