donglang9880 2015-06-14 08:59
浏览 199
已采纳

在html中显示多行

I am having an issue with pulling info from the database and displaying it on the page. In the table I have multiple entries in each column. So I need to pull that info and display it in a descending order from the column id. But with this it displays the rows like this on the page:

### ### ###
#1# #1# #1#
### ### ###

### ### ###
#2# #2# #2#
### ### ###

### ### ###
#3# #3# #3#
### ### ###

I can't figure out what exactly I am doing wrong here. It's been a little bit since I did anything with php and mysql so I may just be writing something incorrectly but I don't know.

<?
require 'dbinfo.php';

   $link = mysqli_connect($servername, $username, $password);
    if (!$link) {
    die('Could not connect: ' . mysqli_error($link));
    }
    mysqli_select_db($link, $database) or die(mysqli_error($link));

    $query = "SELECT `id`, `build`, `buildby`, `description`, `download` FROM `buildlist` ORDER BY id DESC";
    $result = mysqli_query($link,$query) or die(mysqli_error($link));

    $row = mysqli_fetch_row($result);
    $num = mysqli_num_rows($result);
    ?>

<?
      $num = mysqli_num_rows($result);
      if($num) {
        while( $row = mysqli_fetch_array($result) ) {
    ?>

    <article class="one_third">
      <h2>Build <? echo $row['build'] ?></h2>
      <img src="images/80x80.gif" alt="">
      <p>Build by <? echo $row['buildby'] ?><br />
      <br /><br /><br />
      <? echo $row['description'] ?><br />
      <br / >
      <a href="<? echo $row['download'] ?>" class="download">Download this build</a></p><br />
    </article>

    <article class="one_third midbox">
      <h2>Build <? echo $row['build'] ?></h2>
      <img src="images/80x80.gif" alt="">
      <p>Build by <? echo $row['buildby'] ?><br />
      <br /><br /><br />
      <? echo $row['description'] ?><br />
      <br / >
      <a href="<? echo $row['download'] ?>" class="download">Download this build</a></p><br /><br /><br />
    </article>

    <article class="one_third lastbox">
      <h2>Build <? echo $row['build'] ?></h2>
      <img src="images/80x80.gif" alt="">
      <p>Build by <? echo $row['buildby'] ?><br />
      <br /><br /><br />
      <? echo $row['description'] ?><br />
      <br / >
      <a href="<? echo $row['download'] ?>" class="download">Download this build</a></p><br />
    </article>

    <? }} ?>
  • 写回答

3条回答 默认 最新

  • dtcyv3985 2015-06-14 09:41
    关注

    There is some mistakes in your code. First you don't need to fetch a row before the loop. Second - you should use mysqli_fetch_assoc instead of mysqli_fetch_array or use $row[index] instead of $row[string].

    Here is correct code:

    <?
        require 'dbinfo.php';
    
        $link = mysqli_connect($servername, $username, $password);
    
        if (!$link) {
            die('Could not connect: ' . mysqli_error($link));
        }
        mysqli_select_db($link, $database) or die(mysqli_error($link));
    
        $query = "SELECT `id`, `build`, `buildby`, `description`, `download` FROM `buildlist` ORDER BY id DESC";
        $result = mysqli_query($link,$query) or die(mysqli_error($link));
    
        $num = mysqli_num_rows($result);
        if($num) {
            while( $row = mysqli_fetch_assoc($result) ) {
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'