我正在编写一个代码,通过该代码我有两个表(表1命名为approved_requests,表2命名为canceled_requests)。我想要做的是将表1中的列(event_title)中的值与表2中的列(也称为event_title)中的值进行比较。如果它们匹配,我想显示文本,而如果它们不是'匹配我要显示一个按钮。最好的方法是什么?
这是我到目前为止所做的:
$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>
}
答案 0 :(得分:0)
我找到了一个简单的问题解决方案
$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);