我有2个表: wp_users 和 CD2015_EmailIncidents 。我在phpmyadmin中发了一个查询。
Thats通过电子邮件加入两个表,并创建一个包含以下字段的表:
Email - Reference - Type - Site
我想要做的是当用户登录成员区域时,表格只显示他们的数据。
所以将表过滤到current_user电子邮件到表
继承了我的代码,但它显示了所有数据:
<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT Site, Type, Reference, Email
FROM CD2015_EmailIncidents AS s
JOIN wp_users AS c
ON s.Email = c.user_email
WHERE c = '<?php $current_user->user_email ?>' ");
//echo "<pre>"; print_r($result); echo "</pre>";
echo "Reference"." "."Site"." "."Type"."<br><br>";
foreach($result as $row)
{
echo $row->Reference." ".$row->Site." ".$row->Type."<br>";
}
?>
任何帮助都会很棒!...谢谢
答案 0 :(得分:0)
我越来越近了吗?
<?php
global $wpdb;
$current_user = wp_get_current_user();
$result = $wpdb->get_results( "SELECT Site, Type, Reference, Email
FROM CD2015_EmailIncidents
JOIN $current_user->user_email
ON CD2015_EmailIncidents.Email= $current_user->user_email ");
echo "Email:"." "."Type:"."<br><br>";
foreach($result as $row) {
echo $row->Email." ".$row->Type."<br>";
}
?>