blue-genie Posted March 26, 2010 Share Posted March 26, 2010 have a look at what i'm trying to do. in my database, i have fields 1 - 11 for each game however not all those field will have data. Is there a way I can get my xml to only go up to where it's not null? i.e say this query returns 2 items. the first item only has 1 prize, the second one has 3. can i get the xml to look like this: <dataxml> <row gameID="65"> <gameName>banana</gameName> <prize id="1">another prize 1</prize> </row> <row gameID="666"> <gameName>carrot</gameName> <prize id="1">another prize 1</prize> <prize id="2">another prize 2</prize> </row> </dataxml> $result = mysql_query("SELECT * FROM gamedetails LEFT JOIN gamePrizes ON gameID = gamePrizeID where prizeID is NOT NULL"); echo '<?xml version="1.0"?>'; echo '<dataxml>'; 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); much thanks. Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/ Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Share Posted March 26, 2010 $result = mysql_query("SELECT * FROM gamedetails LEFT JOIN gamePrizes ON gameID = gamePrizeID where prizeID is NOT NULL"); echo '<?xml version="1.0"?>'; echo '<dataxml>'; if (mysql_num_rows($result)){ while ($row = mysql_fetch_array($result)) { echo '<row gameID="'.$row['gameID'].'">'; echo "<gameName>".$row['gameName']."</gameName>"; if(isset($_GET['rank1'])){ echo "<prize id='1'>".$row['rank1']."</prize>"; } if(isset($_GET['rank2'])){ echo "<prize id='2'>".$row['rank2']."</prize>"; } .....etc 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); Maybe? Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/#findComment-1032106 Share on other sites More sharing options...
blue-genie Posted March 26, 2010 Author Share Posted March 26, 2010 hey. no that didn't work. never echos those even if field is not null. Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/#findComment-1032110 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Share Posted March 26, 2010 I don't want to send you on a goose chase since i'm not actively trying this code, but what about instead of $_GET['rank#'] you tried $row['rank#'] Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/#findComment-1032114 Share on other sites More sharing options...
blue-genie Posted March 26, 2010 Author Share Posted March 26, 2010 i was hoping there was a way to do it within the select statement. $row['rank#'] doesn't work either, but thanks anyway. Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/#findComment-1032131 Share on other sites More sharing options...
blue-genie Posted March 26, 2010 Author Share Posted March 26, 2010 i got assistance from another forum. thanks. Link to comment https://forums.phpfreaks.com/topic/196574-need-to-make-while-loop-not-add-null/#findComment-1032197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.