代码没有错误,但它没有显示任何数据

时间:2015-05-15 02:16:58

标签: php mysqli

我正在制作一个wallpost脚本,页面没有错误,我已经检查了数据库(查询在那里工作)并且我已经尝试了我认为我能做的一切,但它不会工作。我不知道还有什么可做的,如果你对它为什么不能工作有任何想法,请告诉我。 PS:数据库中有一些虚拟数据。

<?php
    include 'inc/dbc.php';
    include 'inc/functions.php';

    if(isset($_GET['user']) && !empty($_GET['user'])) {
        $username = $_GET['user'];
    } else {
        $username = $_SESSION['username'];
    }

    $my_name = $_SESSION['username'];
    $firstname = getuser($username, 'firstname');
    $middlename = getuser($username, 'middlename');
    $lastname = getuser($username, 'lastname');
    $aboutme = getuser($username, 'aboutme');
    $email = getuser($username, 'email');
    $dob = getuser($username, 'dob');
    $address = getuser($username, 'address');
    $website = getuser($username, 'website');
    $country = getuser($username, 'country');
    $city = getuser($username, 'city');
    $state = getuser($username, 'state');
    $phone = getuser($username, 'phone');
    $gender = getuser($username, 'gender');
    $rank = getuser($username, 'rank');
    $avatar = getuser($username, 'avatar');
    $reg_date = getuser($username, 'reg_date');
?>
<?php
    if (loggedIn() == true) {
        $chech_posts = mysqli_query($mysqli, "SELECT * FROM wallposts WHERE posted_to = '$username' AND deleted = 0 ");
        $check = mysqli_num_rows($chech_posts);

        if ($check == false) {
            echo '<li>Error Getting posts</li>';
        } else {
            while ($run = mysqli_fetch_array($check)) {
                $post_id = $run['post_id'];
                $postby = $run['posted_by'];
                $postto = $run['posted_to'];
                $post = $run['post'];
                $post_date = $run['post_date'];
                $post_time = $run['post_time'];

                $p_avatar = getuser($postby, 'avatar');
                $p_first = getuser($postby, 'firstname');
                $p_last = getuser($postby, 'lastname');
?>
    <li class='wall' id='<?php echo $post_id;?>'>
        <div class='post'>
            <div class='post-container'>
                <div class='post-header'>
                    <div class='pull-left'><?php echo $postby;?></div>
                    <div class='post-img'><img src="images/users/<?php echo $p_avatar;?>" alt="<?php echo $p_first . ' ' . $p_last  . '\'s Profile Picture' ;?>" class="img-circle" align="middle"></div>
                    <div class='pull-right'><?php echo $post_date?></div>
                </div>
                <div class='post-body'>
                    <p><?php echo $post;?></p>
                </div>
                <div class='post-footer'>
                    <div class='lk-cmt-shr'>
                    </div>
                    <span id='comments'>

                    </span>
                </div>
            </div>
        </div>
    </li>
<?php
            }
        }

    } else {
        echo '<li>You must be <a href="index.php">logged</a> in to view ' . $firstname . '\'s posts.</li>';
    }
?>

2 个答案:

答案 0 :(得分:2)

让我们在<?php这两行之后添加并刷新页面。它可以突出显示错误。

error_reporting(E_ALL);
ini_set('display_errors','On');

答案 1 :(得分:0)

我终于得到了它的工作,但我不知道为什么这是一个问题/解决方案,但如果你这样做,请向我解释。无论如何,为了解决我的问题,我拿出了第二个if语句,而只是使用了while循环。我希望这是有道理的。谢谢大家的帮助:D。