PHP 拒绝在框架网格中显示 mysql 数据

PHP refuses to display mysql data in framework grid

我一直面临无法显示来自 MySQL 数据库的数据的问题,当我这样做时

<?php
$servername = "localhost";
$username = "sandpit";
$password = "sand";
$dbname = "sandpit";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT title,url FROM items";
$result = $conn->query($sql);

while ($row = $result->fetch_array()) {
  echo $row["url"];
  echo "</br>";

} ?>

它可以显示这个 (http://puu.sh/eDkcF/a95af62676.png), 但是当我引入这样的框架结构来试图美化它时,

<?php
 $servername = "localhost";
$username = "sandpit";
$password = "sand";
$dbname = "sandpit";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT title,url FROM items";
$result = $conn->query($sql);
?>
 <doctype html>
 <head>
 <meta charset="utf-8" >
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <title>Foundation | Welcome</title>
 <link rel="stylesheet" href="css/foundation.css" />
 <script src="js/vendor/modernizr.js"></script>
    </head>
   <body>
    <? while($row = $result->fetch_array()){
      echo'<div class="row">
      <div class="large-12 columns">
      <ul class="small-block-grid-3">
      <li>$row['url']</li>
      </ul>
      </div>
      </div>;
} ?>

</body>
</html>

根据我所看到的,这不起作用。它给出了这个 (http://puu.sh/eDjUD/0b5e9b1770.png).

的结果

我使用的框架是Foundation,感谢阅读和提供帮助,预期效果是获得块状网格显示。

谢谢

查理

试试这个:

    <? while($row = $result->fetch_array()){
  echo'<div class="row">
  <div class="large-12 columns">
  <ul class="small-block-grid-3">
  <li>'.$row['url'].'</li>
  </ul>
  </div>
  </div>';

} ?>

您的代码因 url 周围的引号而中断,并且末尾缺少 '。

<? while($row = $result->fetch_array()){
      echo"<div class='row'>
      <div class='large-12 columns'>
      <ul class='small-block-grid-3'>
      <li>$row['url']</li>
      </ul>
      </div>
      </div>";
} ?>

因为不解析单引号中的变量。

$name = 'John Wick';
echo 'Hi, $name'; // prints out 'Hi, $name'
echo "Hi, $name"; // prints out 'Hi, John Wick'

您应该在打印变量之前结束引号,或者使用双引号(或此处文档 synthax)。

<?php while($row = $result->fetch_array()){
      echo'<div class="row">
               <div class="large-12 columns">
                   <ul class="small-block-grid-3">
                       <li>' . $row['url'] . '</li>
                   </ul>
               </div>
           </div>';
} ?>