PHP code not working properly after first echo function

时间:2018-03-25 21:06:12

标签: 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 个答案:

答案 0 :(得分:1)

在玩了我的LAMP堆栈的设置之后,我意识到我已经明确地配置了PHP 5,而我已经下载了PHP 7.一旦我修正了差异,一切都按预期工作。尽管如此,感谢您的帮助。