...

View Full Version : If Else in two different tables



thilss0o
03-13-2010, 03:12 AM
im trying to get an if else statement that finds out if the field is equal to another field in another table

sorta like this


if ($field1(of-table-a) == $field1(of-table-b) {
echo "1";
} else {
echo "0";
}

can't figure out a way to do this, but im thinking its simple and i just dont know

thanks

masterofollies
03-13-2010, 03:55 AM
The way to do this is like this.

Create queries for the information you want to pull.

$q1 = mysql_query("SELECT name FROM users WHERE id='$id'");
$q1row = mysql_fetch_array($q1);

$q2 = mysql_query("SELECT weaponid FROM skills WHERE id='5'");
$q2row = mysql_fetch_array($q2);

Now you can use the IF and ELSE statement for two tables.


if (($q1row['name'] == 'Mark') && $q2row['weaponid'] == '71')
{
//This matches
}
else
{
//doesn't matter
}

thilss0o
03-13-2010, 05:03 AM
Ok yea, I was thinking that but I wasn't sure how to write it. Thanks.

masterofollies
03-13-2010, 02:33 PM
Welcome

Dormilich
03-13-2010, 07:16 PM
you can also combine the two queries into one.

SELECT
t1.name AS name,
t2.weaponid AS weaponid
FROM
users AS t1
LEFT JOIN
skills AS t2
WHERE
t1.id = '$id' AND t2.id = 5



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum