为什么不显示帖子名称?

时间:2019-07-18 20:27:31

标签: php web

将显示一个名称或消息“ array”,而不是帖子的名称。显示记录数,但没有标题和描述。如果使用while循环,则显示表中一条记录的名称。如何在表中显示所有记录的名称和描述?

</head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

<body>
  <?php
    require_once 'connection.php'; // подключаем скрипт

    $link = mysqli_connect($host, $user, $password, $database) 
        or die("Ошибка " . mysqli_error($link)); 

    $query ="SELECT * FROM tovars "; 

    $result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
    if($result)
    {
        $rows = mysqli_fetch_row($result);
        echo $rows['name'];
        // очищаем результат
        mysqli_free_result($result, MYSQL_ASSOC);
    }

    mysqli_close($link);
    ?>

    <div class="col-sm-4">

      <p>Список постов пуст</p>

      <table class="table">
        <tr>
          <th>
            <?php echo $data['name'];?>
          </th>
          <th>Редактировать</th>
          <th>Удалить</th>
        </tr>
      </table>
    </div>


    <?php foreach ($rows as $row): ?>

    <div class="row">
      <div class="col-md-3">
        <a href="#" class="thumbnail">
          <img src="http://placehold.it/260x180" alt="">
        </a>
      </div>
      <div class="col-md-9">
        <h4>
          <a href="#">
            <?=$row['name']?>
          </a>
        </h4>
        <p>
          <?php echo $select['name'];?>
        </p>
        <p><a class="btn btn-info btn-sm" href="#">Read more</a></p>
        <br/>
        <ul class="list-inline">
          <li><i class="glyphicon glyphicon-user"></i> by <a href="#">John</a> | </li>
          <li><i class="glyphicon glyphicon-calendar"></i> Sept 16th, 2012 | </li>
        </ul>
      </div>
    </div>
    <hr>
    <?php endforeach; ?>
</body>

0 个答案:

没有答案