PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ok I am still new to PHP and am having trouble with this "if"
It should only display the table and info if $mem_type == Family, if $mem_type is anaything else I want it to do nothing. But I am always seeing the table, but the display of SQL results is working as it should. (not seeing when $mem_type does not == Family)
What did i do wrong?
<?php
// Chech to see if membership type is Family, if ttrue return all family members name and call in HTML table.
// Get a specific result from the table
if ($mem_type == Family)
$result = mysql_query("SELECT pn_name, pn_uname FROM _users WHERE barc_id='$barc_id'")
or die(mysql_error());
echo "<br /><table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
<caption><b>All Family Members</b></caption>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table><br />\n";
?>
Now as far as the string needing quotes, do they, or should they? I have 6 others that do not have qqoes and they are working ok. This if statement also works ok with or with out them now?
// Chech to see if membership type is Family, if ttrue return all family members name and call in HTML table.
// Get a specific result from the table
if ($mem_type == 'Family')
{$result = mysql_query("SELECT pn_name, pn_uname FROM _users WHERE barc_id='$barc_id'") or die(mysql_error());
echo "<br /><table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><caption><b>All Family Members</b></caption>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table><br />\n";
}
?>
It's good practice to enclose string literals in quotes. PHP is smart enough to figure out what you meant, but if you had PHP set to display all errors, you would get a notice saying that you were making a call to an undefined constant.