我的网站是Design Spicy 我试图在wordpress中获取自定义表数据。我的表中有5个条目,但它只显示第一个条目。为什么?
我想从表中获取所有行。有什么建议吗?
function viewall22()
{
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_savans");
foreach($result as $row)
{
$sitemap = '<?php echo $row[name];?>';
}
}
答案 0 :(得分:1)
试试这个,
function viewall22()
{
global $wpdb;
$sitemap = '';
$result = $wpdb->get_results( "SELECT * FROM wp_savans", ARRAY_A);
foreach($result as $row)
{
$sitemap .= $row[name];
}
echo $sitemap;
}
答案 1 :(得分:0)
function viewall22()
{
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_savans", ARRAY_A);
foreach($result as $row)
{
$sitemap = '<?php echo $row[name];?>';
}
}
答案 2 :(得分:0)
function viewall22()
{
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_savans");
while ($row = mysql_fetch_assoc($result))
{
$sitemap = '<?php echo $row[name];?>';
}
}
答案 3 :(得分:0)
为了您的更多知识,您也可以参考! (替代@ Vidhu Nair )
function viewall22()
{
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_savans");
foreach($result as $key=>$row)
{
$sitemap = $row->name; // Refer as get value by using 'Object'
}
}
谢谢!