I'm working on a code by which I have two tables (table 1 named as approved_requests and table 2 named as canceled_requests). What I was trying to do is to compare values in column (event_title) from table 1 with values in column (also named as event_title) from table 2. And if they match I want to display a text , while if they don't match I want to display a button. What is the best way to do it?
我正在编写一个代码,通过该代码我有两个表(表1命名为approved_requests,表2命名为canceled_requests)。我试图做的是将表1中的列(event_title)中的值与表2中的列(也称为event_title)中的值进行比较。如果它们匹配,我想显示文本,而如果它们不匹配我想要显示一个按钮。最好的方法是什么?
Here what I have so far:
到目前为止我所拥有的:
$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>
}
1 个解决方案
#1
I found a simple solution to my questions
我找到了一个解决问题的简单方法
$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);
#1
I found a simple solution to my questions
我找到了一个解决问题的简单方法
$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);