Jump to content


Photo

Selecting Independent Value


  • Please log in to reply
2 replies to this topic

#1 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 28 September 2006 - 08:57 PM

My MYSQL table looks like this:

id  username  blocked
1         Bob             Jack
21         Bill               Bob
4              Bob                Jane


The problem is, when I call up this table with

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

Say, $recip = Bob, so the username Bob 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.)

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 28 September 2006 - 09:09 PM

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


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



#3 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 28 September 2006 - 09:37 PM

Thanks! That worked perfectly!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users