我正在尝试使用此查询从数据库检索字段的文本值:input type=text name=last_link id=last_link value=?php global $wpdb; $user_ID = get_current_user_id(); $result= $wpdb-get_results( SELECT last_...

我正在尝试使用此查询从数据库检索字段的文本值:
<input type="text" name="last_link" id="last_link" value="<?php global $wpdb; $user_ID = get_current_user_id(); $result= $wpdb->get_results( 'SELECT last_link FROM users WHERE ID = $user_ID'); echo $result; ?>"
我收到的是:
我已经搜索了很多,但我只能找到Class Reference/wpdb
而且我找不到我的错误.
解决方法:
使用$wpdb-> get_var(‘your query’)代替$wpdb-> get_results()
我在查询中发现错误,即您忘记了从wordpress预定义表中检索信息所需的表前缀.
将全局$table_prefix与$wpdb一起使用
像这样:全局$wpdb,$table_prefix
还要确保将您的列last_link添加到tableprefix_users的表中
根据您的要求,使用以下代码检索信息.
<?php
global $wpdb,$table_prefix;
$user_ID = get_current_user_id();
$last_link = $wpdb->get_var('SELECT last_link FROM '.$table_prefix.'users WHERE ID = '.$user_ID);
?>
<input type="text" name="last_link" id="last_link" value="<?php echo $last_link;?>">
如文档中所述
Generic, multiple row results can be pulled from the database with
get_results. The function returns the entire query result as an array.
Each element of this array corresponds to one row of the query result
and, like get_row, can be an object, an associative array, or a
numbered array. If no matching rows are found, or if there is a
database error, the return value will be an empty array. If your
$query string is empty, or you pass an invalid $output_type, NULL will
be returned.
本文标题为:PHP-WordPress:从数据库中检索值


基础教程推荐
- PHP-WordPress:从数据库中检索值 2023-10-08
- 【wordpress】wordpress插件之自动采集发布工具 2023-10-08
- dedecms支付宝支付成功后发送邮件通知站长的方法 2023-07-09
- WordPress在其他PHP文件中使用wp_config.php变量连接到数据库 2023-10-08
- 64MB内存VPS安装Lighttpd-SQLite-PHP搭建WordPress博客教程 2023-10-08
- linux-使用wget在WordPress上进行身份验证 2023-10-08
- PbootCMS伪静态配置教程以及各web容器配置规则 2023-07-08
- WordPress致命错误:在1832行的wp-includes / wp-db.php中,允许的内存大小为536870912字节(试图分配77个字节) 2023-10-08
- 织梦dedecms首页列表页ajax无限下拉加载瀑布流效果 2022-06-23
- php – 如何在wordpress插件中获取会话变量 2023-10-08