Is there a better way of Comparing Two Rows from the same table
Here's the problem. I have a database which has two unique keys. One is page id, the other is user ID. Then there are 60 columns of variables that need to be compared. For example if the rows looked like this:
id | user id | page id | var1 | var2 | var3 | var4 | --- | var60
============================================================================
5 | 20 | null | A | B | null | D | --- | DD
36 | null | 125 | null | B | C | null | --- | DD
I would like to echo 'true'
But if var2 was a null and var60 was a null (so there were no common columns) I would echo 'false'
I can do this with a huge group of if statements but I would like to figure out how to get an if statement that simply said:
if (row id 5 has any columns that match row id 36){
{echo 'true'; }
else
echo 'false';
Isolating each row is easy, this is how I did it. I have a currentUserRS (record set) that returns the user ID for any logged in user from the session variable, and a pageRS (current page RS) that returns the page id. There is a table that sets variables for each user and for each page in the table docSecurity. I just need to see if any of the 60 variables match.
This code reliably identifies the page ID and the current user ID. I'm hoping to get the results I need without writing 60 if statements and then checking to see if any of them are t
rue. BTW, each of the variable fields is unique, for example, var1 is always A or null. No other values are permitted in the table.
Here's my code that grabs the user and page id's.
$checkVal = $row_currentUserRS['id'];
$pageChkVal = $row_pageRS ['id'];
$result = mysql_query("select * FROM docSecurity WHERE securityID = $checkVal");
$result2 = mysql_query("select * FROM docSecurity WHERE pageID = $pageChkVal");
$row = mysql_fetch_array($result );
$row2 = mysql_fetch_array($result2);
echo 'User Security ID: ', $row['id'], ' / Page Security ID', $row2['id'];

