【发布时间】:2014-07-31 18:30:28
【问题描述】:
我是初学者,尝试使用 wordpress 实现以下目标:
用户填写表格后,我将“位置”存储在数组中,然后是 wp_table_wordpress
然后我创建了另一个包含 "location" 的 wp_table,然后我将 wp_table 的内容检索到一个数组中。
所以如果第一个数组中的“位置”与第二个数组中的“位置”匹配 然后返回 true。
但幸运的是我被卡住了!!
/**
* User fill form then data are insert into an wp table then an array
*/
global $wpdb;
$name = $_POST['name'];
$location = $_POST['location'];
$service = $_POST['service'];
$email = $_POST['email'];
$wpdb->insert('wp_searchform',
array(
'name'=>$name,
'location'=>$location,
'service'=>$service,
'email'=>$email
),
array(
'%s',
'%s',
'%s',
'%s'
)
);
/**
* Retrieve data from a wp_table with a mysql join based on location then stored results in an arrays
*/
$results = $wpdb->get_results( "
SELECT pro_name
FROM wp_searchform
JOIN wp_pro ON wp_searchform.location = wp_pro.location
LIMIT 0 , 30
");
if ($arraysAreEqual = ($wpdb[0] == $results[0]))
{
echo $results[0]->pro_name;
}
else{
echo "true";
}
【问题讨论】:
-
$location 不是数组,那你为什么要检查 $location[0]?
-
很好看的夏洛特,我修改了代码,但还是不行
-
var_dump($results);这样做以获得查询结果。您不是首先选择位置。你只会得到字段 pro_name。 -
var_dump 工作,但我得到了输出 => array(1) { [0]=> object(stdClass)#241 (1) { ["pro_name"]=> string(6) "真实性" } } => 我只想得到结果,而不是结构
-
嗯,你也应该在mysql查询中选择位置字段,否则你无法比较位置。 var_dump() 仅用于调试目的。