Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Populate HTML Table with database values

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)) {

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...