【问题标题】:How do you fetch data from the database? [closed]如何从数据库中获取数据? [关闭]
【发布时间】:2021-08-07 09:43:55
【问题描述】:
<div id="report-tbl-holder">
        <table id="report-tbl" class="table table-stripped table-bordered">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Date/Time</th>
                    <th>Person's Code/Name</th>
                    <th>Establishment's/Barangay Code/Name</th>
                    <th>Temperature</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $i = 1;
                $where = ($eid > 0 && is_numeric($eid)) ? " and e.id = {$eid} " : "";
                $tracks = $conn->query("SELECT t.*,Concat(p.firstname,' ',p.middlename,' ',p.lastname)as pname,p.code as pcode, e.name as ename,e.code as ecode from tracks t inner join people p on p.id=t.person_id inner join establishment e on. e.id = t.establishment_id where date_format(t.date_added,'%Y-%m-%d') BETWEEN '{$date_start}' and '{$date_end}' $where order by date(t.date_added) asc");
                while($row=$tracks->fetch_assoc()):

                ?>
                <tr>
                    <td class="text-center"><?php echo $i++; ?></td>
                    <td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
                    <td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
                    <td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>

                </tr>
                <?php endwhile; ?>
            </tbody>
        </table>

我在我的数据库中创建了一个名为“温度”的行,并希望将其包含在我创建的网页上的表格中,但我不知道如何调用新添加的行(温度)的内容来显示。它确实添加了一个新行,因为我在表头中添加了“温度”,但我不知道如何从数据库中正确调用温度值。

【问题讨论】:

标签: php html sql


【解决方案1】:

我认为有一个混淆......这里的“温度”不是一行,而是一列。

您可以尝试在循环中添加以下代码行:

<td><?php echo $row['body_temp'] ?></td>

【讨论】:

    【解决方案2】:

    您可以使用与获取最后一个表列相同的方式从数据库中获取数据。您必须将新添加的列名添加到 $rows 数组中。

    <tr>
         <td class="text-center"><?php echo $i++; ?></td>
         <td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
         <td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
         <td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>
         <td><?=$row['body_temp'] ?></td>
    </tr>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 2013-05-01
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多