我正在尝试使用此查询从数据库检索字段的文本值: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数据库中获取数组值get_results 2023-10-08
- php – WordPress Skeleton,VVV,Multisite和正确的Nginx规则 2023-10-08
- PBOOTCMS栏目/列表标签序号数从第N个开始的办法 2023-07-08
- Windows下搭建个人博客(Apache+MySQL+PHP+WordPress) 2023-10-08
- php – 如何将wordpress数据库中的缩略图转换为外部页面 2023-10-08
- mysql-WordPress访问 2023-10-08
- WordPress搭建安装方法及步骤 2023-10-08
- 搭建WordPress博客程序库 2023-10-08
- php – WordPress数据库错误MySQL服务器已经离开查询 2023-10-08
- dedecms织梦采集的文章发布时间变为1970-1-1的解决办法 2022-09-02
