-1

//对不起英语不好。

我正在编写一个博客脚本,但它并没有像我预期的那样“好”。我收到错误:

Notice: Undefined property: mysqli_result::$fetch_array

现在我知道这意味着我的 MySQLI 查询正在向我返回 NULL 或 false,但我将查询运行到 PHPMyAdmin 以查看它是否错误,但它在那里工作。

我已经尝试使用 var_dump 等进行调试,但我现在卡了一个小时,希望你们能帮助我。我的代码:

    <?php
include_once "header.php";

$queryInfo       = "SELECT id,datum,auteur,comments,tags,titel,omschrijving,image FROM blog ORDER BY datum DESC";
$selectqInfo     = $mysqli->query($queryInfo);
?>
    <div class="row">
            <div class="sixteen columns">
                <div class="breadcrumb">
                    <a href="home" class="first_bc"><span>Home</span></a>
                    <a href="blog" class="last_bc"><span>Blog</span></a>
                </div>
                <div class="page_heading"><h1>Blog</h1></div>
            </div>
        </div>

        <div class="row">
            <!-- Wide Column -->
            <div class="twelve columns">
            <?php
            $stringBlog = array();
            while($stringBlog = $selectqInfo->fetch_array);
            {
            ?>
                <div class="post_item">
                    <div class="pic">
                        <a href="blog_item.html"><img src="<?php $stringBlog['image']; ?>"/><div class="img_overlay"></div></a>
                    </div>
                    <h3 class="post_title"><a href="blog_item.html"><?php $stringBlog['titel']; ?></a></h3>
                    <p class="post_meta">
                        <span class="calendar"><a href="blog.html"><?php $stringBlog['datum']; ?></a></span>
                        <span class="author"><a href="blog.html"><?php $stringBlog['auteur']; ?></a></span>
                        <span class="comments"><a href="blog_item.html"><?php $stringBlog['comments']; ?> reacties</a></span>
                        <span class="tags"><a href=""><?php $stringBlog['tags']; ?></a></span>
                    </p>
                    <p class="post_description"><?php $stringBlog['omschrijving']; ?></p>                   
                </div>
            <?php
            }
            ?>
                <div class="post_item">
                    <div class="pic">
                        <a href="blog_item.html"><img src="images/blog_img2_700.jpg"/><div class="img_overlay"></div></a>
                    </div>
                    <h3 class="post_title"><a href="blog_item.html">Clean and Modern</a></h3>
                    <p class="post_meta">
                        <span class="calendar"><a href="">24 September, 2012</a></span>
                        <span class="author"><a href="">by Admin</a></span>
                        <span class="comments"><a href="">3 Comments</a></span>
                        <span class="tags"><a href="">Web Design</a>, <a href="">Web Development</a></span>
                    </p>
                    <p class="post_description"><?php var_dump($queryInfo, $selectqInfo, $stringBlog); ?>.</p>                  
                </div>

//文本是荷兰语,var_dump的de值为:

string(91) "SELECT id,datum,auteur,comments,tags,titel,omschrijving,image FROM blog ORDER BY datum DESC" object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(8) ["lengths"]=> NULL ["num_rows"]=> int(2) ["type"]=> int(0) } NULL
4

2 回答 2

0

fetch_array 是一个函数,而不是一个 var,所以它应该在 while 循环中附加 '()'。

这可能就是您获得未定义属性而不是方法的原因。

前任:

while($stringBlog = $selectqInfo->fetch_array)

可能需要

while($stringBlog = $selectqInfo->fetch_array())
于 2013-11-09T23:39:39.580 回答
0

它应该是:

while($stringBlog = $selectqInfo->fetch_array()) {
    ...
}

您需要使用调用该函数fetch_array()并且不能将分号放在那里。


更新:您需要echo变量:

while($stringBlog = $selectqInfo->fetch_array()) {
?>
    <div class="post_item">
        <div class="pic">
            <a href="blog_item.html"><img src="<?php echo $stringBlog['image']; ?>"/><div class="img_overlay"></div></a>
        </div>
        <h3 class="post_title"><a href="blog_item.html"><?php echo echo $stringBlog['titel']; ?></a></h3>
        <p class="post_meta">
            <span class="calendar"><a href="blog.html"><?php echo $stringBlog['datum']; ?></a></span>
            <span class="author"><a href="blog.html"><?php echo $stringBlog['auteur']; ?></a></span>
            <span class="comments"><a href="blog_item.html"><?php echo $stringBlog['comments']; ?> reacties</a></span>
            <span class="tags"><a href=""><?php echo $stringBlog['tags']; ?></a></span>
        </p>
        <p class="post_description"><?php echo $stringBlog['omschrijving']; ?></p>                   
    </div>
<?php
}
于 2013-11-09T23:40:49.347 回答