Jump to content

MYSQL Help


Scorpion28

Recommended Posts

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)

}

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.