[英]How to fetch data from mySQL by filtering by email?
i am trying to fetch data from mySQL and I would like to filter the result by email. 我正在尝试从MySQL获取数据,我想通过电子邮件过滤结果。 The only problem is, I want to fetch data from a booking DB, while user emails are stored in a different DB.
唯一的问题是,我想从预订数据库中获取数据,而用户电子邮件存储在另一个数据库中。
When a user books a session, his email is fetched using 用户预订会话时,其电子邮件将使用
<?= $fgmembersite->UserEmail(); ?>
and it is saved in the booking DB under reservation_email 并将其保存在预订数据库的reservation_email下
I tried to use WHERE reservation_email= <?= $fgmembersite->UserEmail(); ?>
我尝试使用WHERE
<?= $fgmembersite->UserEmail(); ?>
= <?= $fgmembersite->UserEmail(); ?>
<?= $fgmembersite->UserEmail(); ?>
. <?= $fgmembersite->UserEmail(); ?>
。
**My question is, what can I do, to fetch data into a table by filtering using an email address from a different DB? **我的问题是,通过使用来自不同数据库的电子邮件地址进行过滤,可以将数据提取到表中怎么办? **
**
<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pwd';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dbname';
mysql_select_db($dbname);
$query = "SELECT * FROM booking_reservation WHERE reservation_email='<?= $fgmembersite->UserEmail(); ?>' ";
$result = mysql_query($query)
or die(mysql_error());
print "
<table class='table table-striped'><tr>
<td width=100>Name:</td>
<td width=100>ID Skype:</td>
<td width=100>indirizzo email:</td>
<td width=100>Richiesta:</td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<tr>";
print "<td>" . $row['reservation_name'] . "</td>";
print "<td>" . $row['reservation_surname'] . "</td>";
print "<td>" . $row['reservation_email'] . "</td>";
print "<td>" . $row['reservation_message'] . "</td>";
print "</tr>";
}
print "</table>";
?>
如果我正确理解了问题,则应该可以在查询中使用数据库名称。
SELECT * FROM `db1`.`table` AS t1 JOIN `db2`.`table` AS t2 ON ...
I am not sure just how you are retrieving the email address from the first db? 我不确定您是如何从第一个数据库中检索电子邮件地址的? But for this I would use SESSIONS in the form of:
但是为此,我将使用以下形式的SESSIONS:
<?php
session_start();
//your authentication script
//then
$_SESSION["email"] = $fgmembersite->UserEmail;
//anythink else you need to do
?>
Then in your script 然后在您的脚本中
$query = "SELECT * FROM booking_reservation WHERE reservation_email=".$_SESSION['email'];
I have not tested this, but should put you in the right direction 我尚未对此进行测试,但是应该向正确的方向发展
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.