Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...