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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题