donqh00404 2018-03-25 21:06
浏览 30
已采纳

第一个echo函数后PHP代码无法正常工作

I've been trying to create a web application that functions like a library system, and I am currently working on building the table that will display all books in the system. However, after I close the first echo statement to start building the table in HTML, the app seems to just stop seeing it as code and prints the rest of the PHP code to the screen.

Here is the code in question:

<?php
        $db = mysqli_connect('34.224.99.227','root','opendoor','library')
            or die ('Could not connect to database');

        $result = mysqli_query($db,'SELECT * FROM book');

        echo '<table id="table_id" class="display">
              <thead>
                <tr>
                    <th>ISBN</th>
                    <th>Title</th>
                    <th>Author</th>
                    <th>Description</th>
                    <th>Status</th>
                </tr>
               </thead>
               <tbody>';

        while($row = mysqli_fetch_array($result)) {
            echo '<tr>';
            echo '<td>' . $row['isbn'] . '</td>';
            echo '<td>' . $row['title'] . '</td>';
            echo '<td>' . $row['author'] . '</td>';
            echo '<td>' . $row['description'] . '</td>';
            echo '<td>' . $row['status'] . '</td>';
            echo '</tr>';
        }

        echo '</tbody></table>';

        mysqli_close($db);
    ?>

And here is the corresponding web page output:

ISBN Title Author Description Status '; while($row = mysqli_fetch_array($result)) { echo ''; echo '' . $row['isbn'] . ''; echo '' . $row['title'] . ''; echo '' . $row['author'] . ''; echo '' . $row['description'] . ''; echo '' . $row['status'] . ''; echo ''; } echo ''; mysqli_close($db); ?>

I'm obviously not too well-versed in PHP, so I'm at a loss as to what the problem could be.

  • 写回答

1条回答 默认 最新

  • dongru3726 2018-03-31 15:00
    关注

    After playing around with the settings of my LAMP stack, I realized that I had apparently configured it with PHP 5 in mind, while I had downloaded PHP 7. Once I fixed the discrepancy, everything worked as intended. Thanks for help nonetheless.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划