如何从两个表中获取数据信息使用php
我想从两个表中获取数据。我在一张桌子上有耐心的名字和姓氏,在另一张桌子上有预约时间。我使用下面的方法,但它给出了一个错误:如何从两个表中获取数据信息使用php
SELECT
PatientMaster.PatientFirstName,
PatientMaster.PatientLastName,
ProviderAppointmentListings.AppointmentTime
FROM PatientMaster
JOIN ProviderAppointmentListings
ON PatientMaster.PatientID = ProviderAppointmentListings.PatientID
$result = mysql_query($query) OR die(mysql_error());
$rows = array();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo json_encode($rows);
它打印在这里查询空
将帖子
尝试:
$query="SELECT PatientMaster.FirstName,PatientMaster.LastName,ProviderAppointmentListings.AppointmentTime
FROM PatientMaster JOIN ProviderAppointMentListings ON PatientMaster.PatientID = ProviderAppointmentListings.PatientId";
$result = mysql_query($query) or die(mysql_error());
如果出现MySQL错误,那么您的查询一定有问题。
它givning同样的错误MySQL的取指[] – 2012-03-21 06:18:15
尝试使用@ramil阿米尔的代码 – prukuhkoo 2012-03-21 06:19:31
是我使用@ramil代码,但再次相同的错误 – 2012-03-21 06:21:18
试试这个:
$query = "SELECT ... ";
$result = mysql_query($query);//<=== add this line
$rows = array();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo json_encode($rows);
mysql_fetch_assoc():提供的参数不是一个有效的MySQL结果它给我这个错误,当我运行代码 – 2012-03-21 06:16:01
@Atabtab你真的放置了'select ...'吗? – 2012-03-21 06:17:23
什么文学放置意味着对不起,我没有得到那 – 2012-03-21 06:19:08
您可以复制/粘贴确切的错误信息吗?也试试这个简单的JOIN
查询:
SELECT
PatientMaster.PatientFirstName,
PatientMaster.PatientLastName,
ProviderAppointmentListings.AppointmentTime
FROM PatientMaster, ProviderAppointmentListings
WHERE
PatientMaster.PatientID = ProviderAppointmentListings.PatientID
谢谢我已得到解决方案工作 – 2012-03-21 08:42:44
请报出确切的错误信息。更好的是,使用搜索来搜索与此确切的错误消息的其他问题。我相信你会找到很多。 – deceze 2012-03-21 06:14:24
表之间的关系?它是一对一还是一对多? – 2012-03-21 06:18:42
@shiplu如何检查关系B/C我有服务器上的客户端数据库如何检查是否存在关系 – 2012-03-21 06:33:35