首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用foreach比较两个表的结果

问使用foreach比较两个表的结果
EN

Stack Overflow用户
提问于 2013-04-30 11:02:23
回答 1查看 127关注 0票数 0

我在数据库中有两个表,我想使用ist表的结果并将其与第二个表进行比较,例如:

代码语言:javascript
复制
// 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,如下所示:

代码语言:javascript
复制
select * from DN where mtMsgId = 'the whole above result'
EN

回答 1

Stack Overflow用户

发布于 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的结果感兴趣。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16291511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档