我正在尝试使用此查询从数据库检索字段的文本值: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:从数据库中检索值


- 织梦dedecms最全的清除文档的sql语句 2022-06-24
- 织梦dedecms点击数统计控制(刷新页面不新增点击数) 2022-07-20
- PbootCMS伪静态配置教程以及各web容器配置规则 2023-07-08
- 怎么安装使用PbootCMS网站模板 2023-07-08
- pbootcms去除ueditor编辑器图片自动添加的title和alt属性 2023-07-08
- dedecms织梦列表页标题增加页码的方法 2022-07-22
- 织梦采集标题不完整的解决方法,修改标题长度 2022-07-14
- 织梦DedeCMS如何实现文章列表隔行换色变样式 2023-07-08
- pbootcms文章插入图片不固定宽高的办法 2023-07-08
- PbootCMS网站标题描述等标签限制字数的办法 2023-07-08