使用数据库值填充HTML表 [英] Populate HTML Table with database values

查看:78
本文介绍了使用数据库值填充HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含城市,人,就业状态.我想使用PHP使用此值填充html表,第一个td将包含一个城市,下一个将包含该城市的总人数,而第三个td将包含雇用的总人数.通常,我使用while填充表,但是这一步我不知道如何进行mysqli查询,如果while也可以使用,请检查解决方案,但找不到,在这里呆了几天.

I have a table that contains city, person, employment_status. I want to populate my html table with this values using PHP, the first td will contain a city the next will contain the total number of people in that city and the third td will contain the total number of people employed. Normally I populate my table using while but this one I don't know how to go about the mysqli query and if while will also work, checked for a solution but can't find, been stuck here for days.

                                      <table class="table table-striped table-advance table-hover search-table" >
                         <tbody>
                       <thead>
                          <tr>
                             <th><i class="icon_profile"></i> city</th>
                             <th><i class="icon_pin_alt"></i> Total number of people</th>
                             <th><i class="icon_pin_alt"></i> no of pepople employed</th>

                          </tr>
                          </thead>

                           <?php
            $sql = "SELECT COUNT(DISTINCT city) FROM user"; 
            $q=$conn->query($sql);
           while ($row = mysqli_fetch_array($q)) {

卡在这里,它是查询的一部分,在db中没有创建向我提供此值的行

am stuck here, the query part of it, there is no row created in db to provide me this values

推荐答案

人们在评论中建议.您必须显示到目前为止所做的一切.但是这段代码可能会有所帮助.我正在使用mysqli连接.

As the people suggested in the comments. You'll have to show what have you done so far.But this code may come helpful.I am using using mysqli connection.

<table>
<thead>
<tr>
    <th>City</td>
    <th>Person</td>
    <th>Employment Status</td>
</tr>
</thead>
<tbody>
<?php
$SELECT = mysqli_query($conn,"SELECT * FROM `table`");
if($SELECT != false)
{
    while($rows = mysqli_fetch_array($SELECT))
    {
        echo "
        <tr>
            <td>".$rows["city"]."</td>
            <td>".$rows["person"]."</td>
            <td>".$rows["employment_status"]."</td>
        </tr>
        ";
    }
}
else
{
    echo "
        <tr>
        <td colspan='3'>Something went wrong with the query</td>
        </tr>
    ";
}
?>
</tbody>
</table>

这篇关于使用数据库值填充HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆