Mysqli查询不提取数据库值

时间:2016-07-21 09:29:12

标签: php mysql mysqli

我正在尝试使用php 7.0,因为每个人都建议我从这里开始,因为5.6已被删除。但在编写代码后,我无法从数据库中获取值。我在这做什么错。谢谢

//这是我的约会页//

<div class="col-lg-10">
    <?php  include('config.php');
    $query = mysqli_query('select * from about ');
    while($row = mysqli_fetch_array($query)){
    ?>

    <h5>
    <?php echo $row['about_desc'] ;?>
    <br>
    <br>
    <?php echo $row['about_desc1']; ?>
    <br>
    <br>
    <?php echo $row['about_desc2'] ;?>
    <br>
    <br>
    <?php echo $row['about_desc3'] ;?>
    <br>
    <br>
    <?php echo $row['about_desc4']; ?> 

    </h5>
    <hr class="featurrate-divider">
    <?php
    }
    ?>
    </div>
</div>

<div id="tab-1">
    <?php  include('config.php ');
    $query = mysqli_query('select * from news LIMIT 0,2');
    while($row = mysqli_fetch_array($query)){
    ?>
    <div class="news">
        <h4><u><?php echo $row['news_name']; ?></u></h4>
        <h5><font color="black"><?php echo $row['dat']; ?></font></h5>

        <p><?php echo $row['news_desc']; ?></p>
        <a href="index.php?con=8">se mer >></a>
    </div>
    <hr class="featurrate-divider">

    <?php
    }
    ?>
</div>

//这是我的config.php文件//

<?php
$connection = mysqli_connect('localhost','root','','dandelion') or die(mysqli_error($connection));
?>

寻找学习者的好建议。谢谢

2 个答案:

答案 0 :(得分:1)

您的“关于我们”页面应如下所示:

<body>

                                <div class="col-lg-10">
                                    <?php  include('config.php');
                    $query = mysqli_query($connection, 'select * from about ');
                    while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
                       ?>

                         <h5>
                        <?php echo $row['about_desc'] ;?>
                                            <br>
                                                <br>
                                                    <?php echo $row['about_desc1']; ?>
                                                    <br>
                                                        <br>
                                                            <?php echo $row['about_desc2'] ;?>
                                                            <br>
                                                                <br>
                                                                    <?php echo $row['about_desc3'] ;?>
                                                                    <br>
                                                                        <br>
                                                                            <?php echo $row['about_desc4']; ?> 

                    </h5>
                    <hr class="featurrate-divider">
                                        <?php
                                        }
                                        ?>
                </div>
                </div>

                                <div id="tab-1">
                                     <?php  include('config.php ');
                                    $query = mysqli_query($connection, 'select * from news LIMIT 0,2');
                                    while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
                                       ?>
                                    <div class="news">
                                        <h4><u><?php echo $row['news_name']; ?></u></h4>
                                         <h5><font color="black"><?php echo $row['dat']; ?></font></h5>

                                         <p><?php echo $row['news_desc']; ?></p>
                                        <a href="index.php?con=8">se mer >></a>
                                    </div>
                                    <hr class="featurrate-divider">

                                    <?php
                                    }
                                    ?>
                                </div>



</body>

答案 1 :(得分:0)

如果您的数据库连接成功完成,并且获取数据的问题比使用number.it可能对获取数据有用。

circle.setPosition( window.getSize().x / 2 , window.getSize().y / 2 );

<?php echo $row[o]; ?>

而不是

<?php echo $row[1]; ?>