Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Help understand code

11 like 0 dislike
Found this bit of code that is designed to cause the row color to alternate but I do not understand what $i&1 does. I understand that this is causing the class to alternate but I don't understand what that small piece of code is doing.

Code:
===========================================
// PHP Version
$query = "SELECT Adjective, Noun FROM DrSeussLines";
$result = mysql_query($query);
$i = 0;
print "<table>";
while(($row = mysql_fetch_row($result)) !== false) {
    $i++;
    print "<tr class=\"d".($i & 1)."\">";
    print "<td>".$row[0]."</td>";
    print "<td>".$row[1]."</td>";
    print "</tr>\n";
}
mysql_free_result($result);
print "</table>";  
=====================================
asked 2 years ago by eagle09 (95,490 points)

1 Answer

3 like 0 dislike
This is a ternary operator. This basically says

if(isset($_GET['id']))
{
   $id = intval($_GET['id']);
}
else
{
   $id = 0;
}
answered 2 years ago by biswaskeran (70,430 points)

Related questions

10 like 0 dislike
0 answers
7 like 0 dislike
1 answer
asked 2 years ago by eagle09 (95,490 points)
7 like 0 dislike
0 answers
asked 2 years ago by eagle09 (95,490 points)
7 like 0 dislike
3 answers
7 like 0 dislike
1 answer
asked 2 years ago by eagle09 (95,490 points)