分页到我的示例代码

时间:2018-05-15 14:05:25

标签: php mysql sql pagination

这是我的代码我只需要为我的代码添加分页,我尝试了其他一些例子,但它无法正常工作。

在我的HTML代码中,我添加了分页原始(<<<< 1,2,3,4>>) 它使用数据库连接在Wordpress中工作 该网址类似于?eventid=#ID

我在SO中检查了很多代码和示例但是我失败了

function ee_attendee_list($atts){
    global $wpdb, $post;

    $EVT_ID = $atts['eventid'];
    $post = get_post( $EVT_ID );   

    echo '

        ';

    $sql = "SELECT ATT_fname, ATT_lname, ATT_email, ATT_address, ATT_phone, STA_ID ";
    $sql .= "FROM {$wpdb->prefix}esp_attendee_meta ";
    $sql .= "INNER JOIN {$wpdb->prefix}esp_registration ";
    $sql .= "ON {$wpdb->prefix}esp_attendee_meta.ATT_ID = {$wpdb->prefix}esp_registration.ATT_ID ";
    $sql .= "WHERE {$wpdb->prefix}esp_registration.EVT_ID = %d";

    $attendees = $wpdb->get_results( $wpdb->prepare( $sql, $post->ID ));
    echo '<table class="blueTable">
            <thead>
            <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Address</th>
            <th>State</th>
            <th>Country</th>
            </tr>
            </thead>
            <tfoot><tr>
<td colspan="6">';
echo '

<div class="links"><a href="#">&laquo;</a> <a class="active" href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#">&raquo;</a></div>
</td>
</tr>
</tfoot>
<tbody>';
    foreach($attendees as $attendee){
        $fname = $attendee->ATT_fname;
        $lname = $attendee->ATT_lname;
        $email = $attendee->ATT_email;
        if (empty($attendee->ATT_phone)){ $phone = "No Phone";  } else { $phone = $attendee->ATT_phone; }
        if (empty($attendee->ATT_address)){ $address = "No Address"; } else { $address = $attendee->ATT_address; } 
        $STA_ID = $attendee->STA_ID;


        echo "
            <tr>
                <td>$fname $lname</td>
                <td>$email</td>
                <td>$phone</td>
                <td>$address</td>
                <td>$statename</td>
                <td>$country</td>
            </tr>
            ";

    }
    echo "</tbody>
</tr>
</table> ";
}

0 个答案:

没有答案
相关问题