Scorpion28 Posted November 23, 2011 Share Posted November 23, 2011 I have this code I want to check to see if the id from table1 is in table2. Can anyone help me with that if($checkProfile) { $sql_chk_tbl_username = "SELECT id FROM members_profile WHERE id = '"$_SESSION['face']"'"; $rs_user_list = mysql_query($sql_chk_tbl_username); if(mysql_num_rows($rs_user_list) <= 0) } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 23, 2011 Share Posted November 23, 2011 And what problems are you experiencing? Are you getting errors, what? I definitely see problems in your logic, but you can at least take the two seconds necessary to STATE what, exactly, you need help with. You state I want to check to see if the id from table1 is in table2 But, I don't see a "table1" or "table2" anywhere in your code. I assume "members_profile" is one of the tables, but what is the other table and what is the field of the foreign key reference? Do, you just want ONE check for both tables (which would require just one query) or are you wanting to check the "members_profile" table and then the other table? Quote Link to comment Share on other sites More sharing options...
Scorpion28 Posted November 23, 2011 Author Share Posted November 23, 2011 THE ID FROM THE OTHER TABLE IS $_SESSION['face'] Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 23, 2011 Share Posted November 23, 2011 I'm more than willing to help you, but you are still not really providing any useful information. If you want free help, then take some time to explain your problem. The questions you are asking probably make perfect sense to you since you have the context of the steps you have taken thus far and know what it is you are trying to accomplish. But, the question is vague to us because we don't have that context. If $_SESSION['face'] is the value from the "other" table, then your code above (while not the appropriate implementation) would work to determine if there are any records with that value in the "member_profiles" table. Also, since you already have the value from the first table, your question about I want to check to see if the id from table1 is in table2 is misleading. So, again, I will ask what problems are you experiencing? EDIT: OK, I see your error (basic PHP string concatenation). You should definitely be getting some type of error with that code, so why did you not provide it? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 23, 2011 Share Posted November 23, 2011 if($checkProfile) { $query = "SELECT COUNT(`id`) FROM `members_profile` WHERE `id` = '{$_SESSION['face']}'"; $result = mysql_query($query) or die(mysql_error()); $id_count = mysql_result($result, 0); if(!$id_count) { //ID does not exist } else { //ID does exist } } Quote Link to comment Share on other sites More sharing options...
Scorpion28 Posted November 23, 2011 Author Share Posted November 23, 2011 Thanks I'm about to try it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.