Jump to content

Selecting Independent Value


elis

Recommended Posts

My MYSQL table looks like this:

[b]id  username  blocked[/b]
1         Bob             Jack
21         Bill               Bob
4              Bob                Jane


The problem is, when I call up this table with

[code]bresult = mysql_query("SELECT * FROM blocks WHERE username = '$recip'");
$cresult = mysql_fetch_array($bresult);[/code]

Say, $recip = Bob, so the username [i]Bob[/i] is called up;
and then I compare if with "IF...$userusername ==cresult[blocked]..."
so that if a user is blocked by Bob, they can't contact him.

The problem with this is, if you look at the table, Bob as two people blocked in two rows: Jane and Jack.
So if Jack is trying to contact Bob, he's obviously blocked - but the MYSQL arrangment will read Jane as being blocked and let Jack contact Bob. (I'm sorry if this is getting confusing, I'm fairly poor at explaining things).

So I need a method where the Select function will get the ID, since it's the only independent value, but I'm not sure how to go about this as I don't know what to put for "WHERE ________ = ___________" . (Or if anyone has any other ideas, they'd be much appreciated too.)
Link to comment
Share on other sites

Unless i totally misunderstood you - run it through a while loop

[code]

<?php

$block = false;

$bresult = mysql_query("SELECT * FROM blocks WHERE username = '$recip'");
while($row=mysql_fetch_array($bresult))
{
  if($row["blocked"] == $userusername)
  {
    $block = true;
    break;
  }
}

if($block == true)
{
  echo "User har blocked you, sorry";
}
else
{
// proceed
}
?>

[/code]
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.