0

データベースに 2 つのテーブルがあり、ist テーブルの結果を使用して、次のように 2 番目のテーブルと比較したいと考えています。

// 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 で、次の ような2 つのフィールドがmtMsgIdあります。msgStatus

select * from DN where mtMsgId = 'the whole above result'
4

1 に答える 1

2

JOINを探していると思います。これは SQL で行うことができます。

$result = mysql_query("select s.mtMsgId,j.msgStatus from JN j, SMS s WHERE s.mtMsgId = j.mtMsgId AND s.result = '0' ");

これは、データを取得する 2 つのテーブルに名前を付けます。"SMS" は s、"JN" は j です。結果を s.mtMsgId = j.mtMsgId (それらの mtMsgIds に従って結合) で「同期」し、SMS.result が 0 である結果に関心があります。

于 2013-04-30T03:09:14.543 に答える