blue-genie
asked on
in while loop - check if field is null then break?
i have 11 fields of optional data for each row entry.
when i pull out the data I want it to echo xml node only if there is something there.
$result = mysql_query("SELECT * FROM gamedetails LEFT JOIN gamePrizes ON gameID = gamePrizeID where prizeID is NOT NULL");
what a result as follows (assuming that 2 items are returned, item 1 has something in field 1 and field 2, and item 2 only has something in field 1)
<dataxml>
<row gameID="65">
<gameName>banana</gameName >
<prize id="1">another prize 1</prize>
<prize id="2">another prize 2</prize>
</row>
<row gameID="666">
<gameName>carrot</gameName >
<prize id="1">another prize 1</prize>
</row>
</dataxml>
someone suggested //if(isset($_GET['rank5']) ){, but that didn't work.
code snippet below might have some syntax errors, stripped out some testing stuff, but it's just to show what i've done.
so if there's only 2 prizes I don't want the empty nodes.
when i pull out the data I want it to echo xml node only if there is something there.
$result = mysql_query("SELECT * FROM gamedetails LEFT JOIN gamePrizes ON gameID = gamePrizeID where prizeID is NOT NULL");
what a result as follows (assuming that 2 items are returned, item 1 has something in field 1 and field 2, and item 2 only has something in field 1)
<dataxml>
<row gameID="65">
<gameName>banana</gameName
<prize id="1">another prize 1</prize>
<prize id="2">another prize 2</prize>
</row>
<row gameID="666">
<gameName>carrot</gameName
<prize id="1">another prize 1</prize>
</row>
</dataxml>
someone suggested //if(isset($_GET['rank5'])
code snippet below might have some syntax errors, stripped out some testing stuff, but it's just to show what i've done.
so if there's only 2 prizes I don't want the empty nodes.
if (mysql_num_rows($result)){
while ($row = mysql_fetch_array($result)) {
echo '<row gameID="'.$row['gameID'].'">';
echo "<gameName>".$row['gameName']."</gameName>";
echo "<prize id='1'>".$row['rank1']."</prize>";
echo "<prize id='2'>".$row['rank2']."</prize>";
echo "<prize id='3'>".$row['rank3']."</prize>";
echo "<prize id='4'>".$row['rank4']."</prize>";
echo "<prize id='5'>".$row['rank5']."</prize>";
echo "<prize id='6'>".$row['rank6']."</prize>";
echo "<prize id='7'>".$row['rank7']."</prize>";
echo "<prize id='8'>".$row['rank8']."</prize>";
echo "<prize id='9'>".$row['rank9']."</prize>";
echo "<prize id='10'>".$row['rank10']."</prize>";
echo "<prize id='11'>".$row['rank11']."</prize>";
echo "</row>";
}
} else {
echo '<error>no results</error>';
}
echo '</dataxml>';
mysql_free_result($result);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sheer genius. exactly what I wanted.
while ($row = mysql_fetch_array($result)
if($row['gameID'] =='')
{
break;
}
else
{
// do what you want
}
}