0
$query1= mysql_query("select r.nid from ....");     

$query2= mysql_query("select t.nid from...."); 

Both these queries return a nid. How to compare the 2 returned nid are equal.. I'm just a beginner.

Parthi04
  • 1,081
  • 4
  • 20
  • 39
  • why do need it? you can compere then in query. Do you know how to get data from database using php? do you know how to compare 2 variables in php? – El' May 09 '12 at 07:48
  • where do you like to make that compare? in php code or in sql? – AKZap May 09 '12 at 07:55
  • If you're going to continue doing mysql using PHP (and just started learning) I highly suggest learning PDO instead of using mysql_* . Suggested Reads: http://stackoverflow.com/questions/866860/mysql-vs-pdo http://stackoverflow.com/questions/13569/mysqli-or-pdo-what-are-the-pros-and-cons http://www.php.net/manual/en/book.pdo.php – Event_Horizon May 10 '12 at 05:24

3 Answers3

1
$row1 = mysql_fetch_row($query1);
$row2 = mysql_fetch_row($query2);
if($row1[0] == $row2[0])
{
//something
}
arun
  • 3,637
  • 3
  • 27
  • 53
1

You could do it in pure sql. Like this:

select 
    r.nid 
from 
    ....
WHERE EXISTS
(
    select 
        NULL 
    from
        ....
    WHERE
        t.nid = r.nid 
)
Arion
  • 29,817
  • 9
  • 65
  • 81
1

If you are certainly sure that the query really returns one id, you can speed up checking it by:

$query1 = mysql_query("select r.nid from ...."); 
$query2 = mysql_query("select t.nid from ...."); 
if(mysql_fetch_field($query1, 0) === mysql_fetch_field($query2, 0))
{
    //do something
}
Andrius Naruševičius
  • 7,659
  • 6
  • 44
  • 72