SQL查询结果转入php表 [英] SQL query results into php table
本文介绍了SQL查询结果转入php表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 SQL 查询的结果放入我的 wordpress 站点的表中.
I'm trying to place the results of a SQL query into a table for my wordpress site.
我的表叫做statetable"
My table is called "statetable"
列是 "State"、"num-Asn" 和 "Percent"
The columns are "State", "num-Asn" , and "Percent"
以下是我在自定义 php 模板中的代码.
The following is my code in my custom php template.
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM statetable;");
echo "<table>";
foreach($results as $result){
echo "<tr>";
echo "<td>".$result->State."</td>";
echo "<td>".$result->num-ASN."</td>";
echo "<td>".$result->Percent."</td>";
echo "</tr>";
}
echo "</table>";
?>
我得到一张空表格,其中一个单元格填充了零.我认为这可能不是设置它的最佳方式,或者我的 foreach 循环语法错误.
I get an empty table with one cell filled with zeros. I think this might not be the best way to set it up, or I have the wrong syntax for the foreach loop.
推荐答案
"num-ASN" 是非法标识符名称.检查 $results
中的内容.
"num-ASN" is an illegal identifier name. Check what's in $results
.
这篇关于SQL查询结果转入php表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文