Mysql表在云9中不显示为html表

时间:2014-09-23 07:26:01

标签: php mysql html5 cloud9-ide

嗨我想在云端9上执行以下代码 :

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test | Products</title>
    </head>

    <body>
        <?php
            $con=mysqli_connect(0.0.0.0,"ritikasahay","","trydb");

            if (mysqli_connect_errno()) {
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }

            $result = mysqli_query($con,"SELECT * FROM veg");

            echo "<table border='1'>
            <tr>
                <th>Name</th>
                <th>Price</th>
                <th>Image</th>
            </tr>";

            while($row = mysqli_fetch_array($result)) {
                echo "<tr>";
                echo "<td>" . $row['name'] . "</td>";
                echo "<td>" . $row['price'] . "</td>";
                echo "<td>" . $row['image'] . "</td>";
                echo "</tr>";
            }

            echo "</table>";

            mysqli_close($con);
            ?>
    </body>
</html>

当我执行此代码时,我只得到以下PHP代码而不是表格内容:

Name Price Image "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['name'] . ""; echo "" . $row['price'] . ""; echo "" . $row['image'] . ""; echo ""; } echo ""; mysqli_close($con); ?>

有人可以告诉我,我错了吗?

2 个答案:

答案 0 :(得分:0)

改变这个命令:

$con=mysqli_connect(0.0.0.0,"ritikasahay","","trydb");

喜欢这个:

$con=mysqli_connect("0.0.0.0","ritikasahay","","trydb");

答案 1 :(得分:0)

表格显示一次而不是多次

<!DOCTYPE html>
<html lang="en">
    <head>

        <title>Test | Products</title>

    </head>
    <body>
        <?php
$con=mysqli_connect("0.0.0.0","ritikasahay","","trydb");

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM veg");

//create table
$table = "<table border='1'>
<tr>
<th>Name</th>
<th>Price</th>
<th>Image</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
  //bind rows
  $table .= "<tr>";
  $table .= "<td>" . $row['name'] . "</td>";
  $table .= "<td>" . $row['price'] . "</td>";
  $table .= "<td>" . $row['image'] . "</td>";
  $table .= "</tr>";
}

//close table
$table .= "</table>";

//display table
echo $table;

mysqli_close($con);
?>
    </body>
</html>