使用数据库值填充HTML表

编程入门 行业动态 更新时间:2024-10-25 06:29:34
本文介绍了使用数据库值填充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表

本文发布于:2023-08-05 20:50:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1307981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!