[英]How to display a virtual table generated by MySQL query in HTML page
I have this MySQL
table MONTHNAME
generated by querying from the database using the following script using PHP
.我有这个
MySQL
表MONTHNAME
通过使用PHP
使用以下脚本从数据库查询生成。
$query = 'SELECT monthname(`dateAdded`) as MONTHNAME,sum(`shift1PinCount`+`shift2PinCount`) from `supervisorupdate` WHERE YEAR(`dateAdded`) = YEAR(CURDATE()) group by monthname(`dateAdded`) ORDER BY monthname(`dateAdded`) DESC';
$queryExecute = mysqli_query($conn, $query);
I want to show this table as it is into my HTML
page using PHP
.我想使用
PHP
将这个表格显示到我的HTML
页面中。 As from I know normally we use据我所知,我们通常使用
while($row = mysqli_fetch_array($queryExecute)){
echo $row['someColumnName'];
}
In this case, I can't do that since I am doing some calculations and getting output as a table.在这种情况下,我不能这样做,因为我正在做一些计算并将输出作为表格。 Can someone guide me on how to show this table?
有人可以指导我如何显示这张表吗?
Edit 1编辑 1
Here is a picture of the result that I am getting using phpMyadmin
.这是我使用
phpMyadmin
得到的结果的图片。 So the HTML table should be similar to this所以HTML表格应该类似于这个
So for HTML
side, it should show something like this所以对于
HTML
端,它应该显示如下内容
<table class="table">
<thead>
<tr>
<th scope="col" id="month">Month</th>
<th scope="col" id="sum">Sum</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" id="jan">January</th>
<td id="janPinCount">3456</td>
</tr>
<tr>
<th scope="row" id="feb">February</th>
<td id="febPinCount">443</td>
</tr>
</tbody>
</table>
Try this one, I added an alias on your sum( shift1PinCount
+ shift2PinCount
) column as PinCount.试试这个,我在你的 sum(
shift1PinCount
+ shift2PinCount
) 列上添加了一个别名作为 PinCount。
<?php
$query = 'SELECT monthname(`dateAdded`) as MONTHNAME, sum(`shift1PinCount`+`shift2PinCount`) as PinCount from `supervisorupdate` WHERE YEAR(`dateAdded`) = YEAR(CURDATE()) group by monthname(`dateAdded`) ORDER BY monthname(`dateAdded`) DESC';
$queryExecute = mysqli_query($conn, $query);
?>
<table class="table">
<thead>
<tr>
<th scope="col" id="month">Month</th>
<th scope="col" id="sum">Sum</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($queryExecute)){ ?>
<tr>
<th scope="row" id="<?=$row['MONTHNAME']?>"><?=$row['MONTHNAME']?></th>
<td id="<?=$row['MONTHNAME']?>PinCount"><?=$row['PinCount']?></td>
</tr>
<?php } ?>
</tbody>
</table>
you can do this.你可以这样做。 put this after the table body
把这个放在桌子后面
$row = mysqli_fetch_array($queryExecute);
do{
echo ' <tr>
<th scope="row" id="jan">.$row["MONTHNAME"].</th>
<td id="janPinCount">$row["SUM"]</td>
</tr> '
}while($row = mysqli_fetch_array($queryExecute))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.