Php 比较两个表中的两列并显示结果

Php 比较两个表中的两列并显示结果,php,mysql,html,compare,two-columns,Php,Mysql,Html,Compare,Two Columns,我正在编写一个代码,其中有两个表,表1名为approved_requests,表2名为Cancelled_requests。我试图做的是将表1中event_title列中的值与表2中名为event_title列中的值进行比较。如果它们匹配,我想显示一个文本,如果它们不匹配,我想显示一个按钮。最好的方法是什么 $sql = "select event_title from approved_requests WHERE user_name ='$name' and event_title not

我正在编写一个代码,其中有两个表,表1名为approved_requests,表2名为Cancelled_requests。我试图做的是将表1中event_title列中的值与表2中名为event_title列中的值进行比较。如果它们匹配,我想显示一个文本,如果它们不匹配,我想显示一个按钮。最好的方法是什么

$sql  = "select event_title from approved_requests WHERE user_name ='$name' and event_title not in (select event_title from canceled_requests)" ;
                $result = mysql_query("$sql") or die(mysql_error());
                $num_rows = mysql_num_rows($result); 
以下是我迄今为止的情况:

$name=$_SESSION['name']; //name of the user currently in session
$sql  = "SELECT * FROM approved_requests WHERE user_name ='$name' " ;
            $result = mysql_query("$sql") or die(mysql_error());
            $num_rows = mysql_num_rows($result);         
           $row = mysql_fetch_array($result);

$sql2 = "SELECT * FROM canceled_requests WHERE user_name ='$name'";
            $result2 = mysql_query("$sql2") or die(mysql_error());          
           $row2 = mysql_fetch_array($result2);

if($row['event_title']==row2['event_title']{ ?>

<form action="" method="post">

                    <input type="submit" name="cancel_event" value="Cancel"> 

                </form>
<?php
                }
else {
?>
<b>canceled</b>
}
$sql  = "select event_title from approved_requests WHERE user_name ='$name' and event_title not in (select event_title from canceled_requests)" ;
                $result = mysql_query("$sql") or die(mysql_error());
                $num_rows = mysql_num_rows($result); 

我找到了解决问题的简单方法

$sql  = "select event_title from approved_requests WHERE user_name ='$name' and event_title not in (select event_title from canceled_requests)" ;
                $result = mysql_query("$sql") or die(mysql_error());
                $num_rows = mysql_num_rows($result); 

为什么不直接处理sql中的连接?@nomistic我找到了一个简单的解决方案来完成这项工作:$sql=select event\u title from approved\u requests,其中user\u name='$name'和event\u title不在select event\u title from cancelled\u requests中$结果=mysql\u查询$sql或diemysql\u错误$num_rows=mysql_num_rows$result;