我在数据库中有两个表,我想使用ist表的结果并将其与第二个表进行比较,例如:
// we connect to example.com and port 3307
mysql_connect("localhost", "root", "pass123") or die(mysql_error());
mysql_select_db("PhGateway") or die(mysql_error());
$result = mysql_query("select mtMsgId from SMS where SMS.`result` = '0' ");
while($row = mysql_fetch_array($result))
{
$mtMsgid=$row['mtMsgId'];
}我想将$mtMsgid的结果与另一个表进行比较,然后显示出来,另一个表的名称是DN,它有两个字段mtMsgId和msgStatus,如下所示:
select * from DN where mtMsgId = 'the whole above result'发布于 2013-04-30 11:09:15
我想你是在找人加入。您可以在SQL中执行此操作:
$result = mysql_query("select s.mtMsgId,j.msgStatus from JN j, SMS s WHERE s.mtMsgId = j.mtMsgId AND s.result = '0' ");
这将命名两个要从中获取数据的表,"SMS“为s,"JN”为j。您使用s.mtMsgId = j.mtMsgId‘同步’结果(根据它们的mtMsgIds将它们结合起来),并且您对SMS.result为0的结果感兴趣。
https://stackoverflow.com/questions/16291511
复制相似问题