DBO中的查询限制(Joomla 3.8.1)

时间:2017-11-05 20:54:47

标签: database joomla dbo

我使用JDatabaseDriver与数据库进行交互。 我从官方Joomla文档中获取的下一个代码。 Documentation

<?php
$query = "SELECT 
        wp_posts.*, 
        (SELECT meta_value FROM wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_wp_attached_file' ORDER BY meta_id DESC LIMIT 1) as image 
    FROM wp_posts 
    ORDER BY post_date DESC 
    LIMIT 0, 25";

$result = mysqli_query($connection, $query) or die(mysqli_error($connection));

while ($row = mysqli_fetch_array($result)) {

    $ID           = $row['ID'];
    $post_title   = $row['post_title'];
    $post_date    = $row['post_date'];
    $post_excerpt = $row['post_excerpt'];    
    $post_content = $row['post_content'];  
    $image        = $row['image'];
?>
    <!-- First Blog Post -->

    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3><a href="post.php?p_id=<?php echo $ID; ?>"><font color="white"><?php echo $post_title; ?></font></a></h3>
            <p><span class="glyphicon glyphicon-time"></span> <?php echo humanTiming(strtotime($post_date));  ?></p>
        </div>
        <div class="panel-body">
            <img class='col-md-4' align='left' width='148' src='/wp-content/uploads/<?php echo $image; ?>' alt=''>
            <p><?php echo $post_content; ?></p>
        </div>
        <p align="right"><a class="btn btn-primary" href="post.php?p_id=<?php echo $ID; ?>">Read More <span class="glyphicon glyphicon-chevron-right"> </span></a></p>
    </div>

<?php } ?>

查看上面代码中的最后一行。 setlimit方法在JDatabaseDriver类中不存在,但它在类中声明 - JDatabaseQueryMysqli。 我不理解逻辑或存在一些错误吗?

1 个答案:

答案 0 :(得分:0)

在最新的Joomla 3.8.1中,setLIMIT无法正常工作。您可以选择其他方法 $查询 - &GT; setQuery($查询,开始,偏移量);