<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM student");
while($row = mysql_fetch_array( $results )) {
echo $row['id'];
echo $row['name'];
}
?>
我只是想显示id和name列值。
答案 0 :(得分:0)
mysql_fetch_array
不在wordpress中使用,因为get_results
函数已经获取记录
foreach($results as $results1)
{
echo $results1->id;
echo $results1->name;
}
答案 1 :(得分:0)
试试这个,
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM student");
foreach ( $results as $result ) {
echo $result->id;
echo $result->name;
}
答案 2 :(得分:0)
只需在get_results
之后显示结果,不需要mysql _ fetch
_ array
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM student");
foreach($results as $res)
echo $res->id;
echo $res->name;
}
?>
答案 3 :(得分:0)
试试这段代码:
<?php
global $wpdb;
//Fetch results as associative array
$results = $wpdb->get_results("SELECT * FROM student", ARRAY_A);
//Cycle
for ($i=0; $i<count($results); $i++) {
//Display them
echo $results[$i]['id'];
echo $results[$i]['name'];
}
?>
有关详细信息,请参阅documentation。