Jump to content


Photo

What kind of operator is & ?


  • Please log in to reply
2 replies to this topic

#1 pmzq

pmzq
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 24 April 2006 - 02:26 PM

Hy all,

I've got a part of a code like this :

if ($myrow["has_politics"] & 1) {
$galaxy = "<td width=\"20%\" align=center bgcolor=\"lightblue\">".
"<a class=\"x\" href=\"politics.php\">Politics</a>";
}

The "has_politics" is a resource row from mysql query named $myrow.

But what i don't understand if what does the & 1 mean after it ?

Does it mean if the "has_politics" row = 1 then $galaxy becomes lightblue ? or is it something else ?

Here is the code which sets that value in mysql:

$q = "UPDATE planet set has_politics = has_politics | 1 ".
"WHERE x='$myrow[x]' AND y='$myrow[y]' AND id!='$Planetid'";
$result = mysql_query ($q, $db);

So can someone explain some of this ?

I hope to hear something soon I realy need this

thnx in advance....

pMzQ,

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 April 2006 - 02:38 PM

The single "&" is a bitwise operator meaning "and". See the [a href=\"http://us3.php.net/manual/en/language.operators.bitwise.php\" target=\"_blank\"]fine manual[/a] for an explanation and examples.

Ken

#3 pmzq

pmzq
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 24 April 2006 - 02:45 PM

Thnx for that Ken :)

But what do those Bits mean it isn't the same as typing has_politics == 1

I don't realy understand how bits work do you have any explaning tutorial some where i can look at or could you tell me how it works ?

thnx pMzQ,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users