Page 1 of 1

Excluding a null feild?

Posted: Sat Mar 04, 2006 4:53 pm
by Farkas
I am somewhat new to php I know some but not enough to do anything advanced.

I have a line of code that I would like to ignore a feild if that feild is Null. Say for instance in this code the feild G_Rank has a null entry, I want it to be excluded from the results that are printed out. Sorry if this is covered somewhere and I could read a post to get the answer. I just cannot seem to get this to work like I would want it to work.


// --------------------------------
// Now let's list all of the groups
$query = "
SELECT G_Rank, G_Id
FROM w3t_Groups
";
$sth = $dbh -> do_query($query);

// --------------------------------------------------------------------
// This gets somewhat confusing. Basically we are echoing out a table
// with 3 colums. When we are done listing the groups then we need
// to fill out the rest of the table with nbsp;
echo "<TABLE BORDER=0 WIDTH=\"95%\" ALIGN=\"center\">";
$row =0;
while ( list($Rank,$Id) = $dbh -> fetch_array($sth)) {
if ( ($Id < 5) && ($Id != 5)) { continue; }
if ($row == 0) { echo "<TR>"; }
$row++;
echo "";

echo " <b>$Rank</b>";
echo "";

}
$dbh -> finish_sth($sth);

Posted: Sat Mar 04, 2006 5:10 pm
by a94060
use php tage around php code. the code tag is for when you are typing html or anything else.

Code: Select all

// -------------------------------- 
// Now let's list all of the groups 
$query = " 
SELECT G_Rank, G_Id 
FROM w3t_Groups 
"; 
$sth = $dbh -> do_query($query); 

// -------------------------------------------------------------------- 
// This gets somewhat confusing. Basically we are echoing out a table 
// with 3 colums. When we are done listing the groups then we need 
// to fill out the rest of the table with nbsp; 
echo "<TABLE BORDER=0 WIDTH=\"95%\" ALIGN=\"center\">"; 
$row =0; 
while ( list($Rank,$Id) = $dbh -> fetch_array($sth)) { 
if ( ($Id < 5) && ($Id != 5)) { continue; } 
if ($row == 0) { echo "<TR>"; } 
$row++; 
echo ""; 

echo " <b>$Rank</b>"; 
echo ""; 

} 
$dbh -> finish_sth($sth);

Posted: Sat Mar 04, 2006 8:08 pm
by feyd

Code: Select all

SELECT G_Rank, G_Id
FROM w3t_Groups
WHERE G_Rank IS NOT NULL