我正在尝试将数据从数据库打印到WordPress。但是,它没有按预期工作。我还尝试打印一个简单的变量。
$host="localhost"; // Host name
$username="root"; // username
$password=""; // password
$db_name="bk"; // Database name
// Replace database connect functions depending on database you are using.
mysql_connect("$host", "$username", "$password");
mysql_select_db($db_name);
$tbl_nm="rg";
global $wpdb;
$a=6;
$B=9;
$result = $wpdb->get_results ( "SELECT nm FROM rg" );
foreach ( $result as $print ) {
?><tr><td><?php
echo $print->nm;
print $a+$B;
?></td>
</tr>
<?php }
答案 0 :(得分:0)
嘿,我解决了我的问题,实际上我没有将'mysql_connect()'分配给任何可靠的这是我的代码
$host="localhost"; // Host name
$username="root"; // username
$password=""; // password
$db_name="bk"; // Database name
// Replace database connect functions depending on database you are using.
$con=mysqli_connect("$host", "$username", "$password","$db_name");
$tbl_nm="rg";
global $wpdb;
$result = mysqli_query($con,"SELECT * FROM rg" );
while($row = mysqli_fetch_array($result))
{echo ' <td colspan="0">'.$row['nm'].'</td>';}
?>