I have 2 tables, members_outsidesales and am_insidesales. Members outsidesales contains first name, last name, login, territory id, and password.

am_outsidesales contains a bunch of fields one of which is territory id as well.

What I am trying to do is write a query that based on the users logged in territory id in members_outsidesales, display only the records with matching territory id's in am_outsidesales. I have tried many way to do this but have not been successful up to this point. Any help would be greatly appreciated! Here is what I have now that doesn't work:

$result = mysql_query("SELECT * FROM am_insidesales
 WHERE territoryid='SESS_TERRITORY_ID'") or die(mysql_error()); 

    Your query would seem OK, although the 'SESS_TERRITORY_ID' looks off, should probably be more like:

    $result = mysql_query("SELECT * FROM `am_insidesales`
    WHERE `territoryid`='" . $_SESSION['TERRITORY_ID'] . "';") or die(mysql_error()); 

    Off course, the $_SESSION['TERRITORY_ID'] should be set once the user logs in.

      Thanks for the quick reply. I tried that and it seems to only return records that have a blank territory id. I'm setting the SESS_TERRITORY_ID when the user logs in like this:

      //Login Successful
      			session_regenerate_id();
      			$member = mysql_fetch_assoc($result);
      			$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
      			$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
      			$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
      			$_SESSION['SESS_TERRITORY_ID'] = $member['territory_id'];
      			session_write_close();
      			header("location: outsidesales-member-index.php");
      			exit();
      		}else {

      Any ideas why

      $result = mysql_query("SELECT * FROM `am_insidesales`
      WHERE `territoryid`='" . $_SESSION['TERRITORY_ID'] . "';") or die(mysql_error()); 
      

      would only return the records with that field blank?

        okay, I saw my problem. Thanks iNFERiON for the help.
        I needed

        $_SESSION['SESS_TERRITORY_ID']

        instead of

        $_SESSION['TERRITORY_ID']
          Write a Reply...