douzuita7325 2018-12-18 20:27
浏览 82

使用mySQL中的数据填充HTML DIV

I have a MySQL DB "dorav3" with a table "dtab1" with the below column containing business card info. I also have a php script and HTML page to display the DB data in a HTML table.

My question is how can I go from just populating a table to populating my flip cards below

where I currently do <td><?php echo $row1[0];?></td> for the table

Should I do something like for the flip card?

<body>
<div class="flip-box">
  <div class="flip-box-inner">
    <div class="flip-box-front">
      <h2><?php echo $row1[0];?></h2>
       <h2><?php echo $row1[1];?></h2>
    </div>
    <div class="flip-box-back">
      <h4><?php echo $row1[2];?></h4>
      <h4><?php echo $row1[3];?></h4>
      <h4><?php echo $row1[4];?></h4>
    </div>
  </div>
</div>

I am really stuck!

+--------------------+---------+------+-----+---------+----------------+
| Field              | Type    | Null | Key | Default | Extra          |
+--------------------+---------+------+-----+---------+----------------+
| Title              | text    | YES  |     | NULL    |                |
| Name               | text    | YES  |     | NULL    |                |
| Email              | text    | YES  |     | NULL    |                |
| Website            | text    | YES  |     | NULL    |                |
| Contact            | text    | YES  |     | NULL    |                |
| id                 | int(11) | NO   | PRI | NULL    | auto_increment |
 ----------------------------------------------------------------------

PHP

<?php

// php populate html table from mysql database

$hostname = "localhost";
$username = "xxx";
$password = "xxx";
$databaseName = "dorav3";

// connect to mysql
$connect = mysqli_connect($hostname, $username, $password, $databaseName);

// mysql select query

$query = "SELECT * FROM `dtab1";


// result for method one
$result1 = mysqli_query($connect, $query);

// result for method two 
$result2 = mysqli_query($connect, $query);

$dataRow = "";

while($row2 = mysqli_fetch_array($result2))
{
    $dataRow = $dataRow."<td>$row2[0]</td><td>$row2[1]</td><td>$row2[2]</td><td>$row2[3]</td><td>$row2[4]</td><td>$row2[5]</td><td>$row2[6]</td><td>$row2[7]</td><td>$row2[8]</td><td>$row2[9]</td><td>$row2[10]</td><td>$row2[11]</td><td>$row2[12]</td><td>$row2[13]</td><td>$row2[14]</td><td>$row2[15]</td>";
}

?>

HTML to Populate table

    <body>
        <table>
             <tr>
                <th>Title</th>
                <th>Name</th>
                <th>Email</th>
                <th>Website</th>
                <th>Contact</th>
            </tr>
            </table>
              <?php while($row1 = mysqli_fetch_array($result1)):;?>
            <table>
            <tr>
                <td><?php echo $row1[0];?></td>
                <td><?php echo $row1[1];?></td>
                <td><?php echo $row1[2];?></td>
                <td><?php echo $row1[3];?></td>
                <td><?php echo $row1[4];?></td>
            </tr>
        </table>
        <?php endwhile;?>
    </body>
</html>

What I want to do next is populate a more rich format with my data.

HTML to Populate cards

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="flip-box">
  <div class="flip-box-inner">
    <div class="flip-box-front">
      <h2>Title</h2>
       <h2>Name</h2>
    </div>
    <div class="flip-box-back">
      <h4>Email</h4>
      <h4>Website</h4>
      <h4>Contact</h4>
    </div>
  </div>
</div>
<div class="flip-box">
  <div class="flip-box-inner">
    <div class="flip-box-front">
      <h2>Title</h2>
       <h2>Name</h2>
    </div>
    <div class="flip-box-back">
      <h4>Email</h4>
      <h4>Website</h4>
      <h4>Contact</h4>
    </div>
  </div>
</div>
<div class="flip-box">
  <div class="flip-box-inner">
    <div class="flip-box-front">
      <h2>Title</h2>
       <h2>Name</h2>
    </div>
    <div class="flip-box-back">
      <h4>Email</h4>
      <h4>Website</h4>
      <h4>Contact</h4>
    </div>
  </div>
</div>

</div>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • du0531 2018-12-18 22:12
    关注

    i am not really getting what u want to do but i think this should work :

    <?php while($row1 = mysqli_fetch_array($result1)):;?>
    <div class="flip-box">
    <div class="flip-box-inner">
    <div class="flip-box-front">
    <h2><?php echo $row1[0];?></h2>
    <h2><?php echo $row1[1];?></h2>
    </div>
    <div class="flip-box-back">
    <h4><?php echo $row1[2];?></h4>
    <h4><?php echo $row1[3];?></h4>
    <h4><?php echo $row1[4];?></h4>
    </div>
    </div>
    </div>
    <?php endwhile;?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)