techiefreak05 Posted September 24, 2006 Share Posted September 24, 2006 i have this code thats supposed to show your friends' bulletins, and if there are no bulletins, instead of having a blank space. it shouls display text saying "No Bulletins. Tell your friends to post some!": heres the code...everything works except the part where its supposed to say no bulletins.. cuz right now no buletins are posted. and its not displaying the no bulletins text.[code]<?php$user = $_SESSION[username];$queryF="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";$resultF=mysql_query($queryF);while($array=mysql_fetch_assoc($resultF)){$poster=$array[friend];$queryB="SELECT * FROM `bulletins` WHERE `from` = '$poster' ORDER by 'id' DESC";$resultB=mysql_query($queryB);while($array=mysql_fetch_assoc($resultB)){if($queryB = 0){echo "No Bulletins. Tell your friends to post some!!";}else{echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#548099><td height=28><b><font color=white>From: <a href='getInfo.php?user=" . $array['from'] . "' class='hidden'>" . $array['from'] . "</a></b><br><b>Date: </b>" .$array['date']; echo "</b></font></td></tr></table>"; echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#356B8B><td height=25><center><a href=\"showBulletin.php?id=".$array['id']."\" class=\"nav\">Subject: ".$array['subject']."</a></center>"; echo "</td></tr></table><br><br>";} }}?>[/code] Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 24, 2006 Share Posted September 24, 2006 this should work[code]<?php$user = $_SESSION[username];$queryF="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";$resultF=mysql_query($queryF);while($array=mysql_fetch_assoc($resultF)){$poster=$array[friend];$queryB=mysql_query("SELECT * FROM `bulletins` WHERE `from` = '$poster' ORDER by 'id' DESC"); if($queryB == ""){ echo "No Bulletins. Tell your friends to post some!!"; } else { while($array=mysql_fetch_assoc($queryB)){ echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#548099><td height=28><b><font color=white>From: <a href='getInfo.php?user=" . $array['from'] . "' class='hidden'>" . $array['from'] . "</a></b><br><b>Date: </b>" .$array['date']; echo "</b></font></td></tr></table>"; echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#356B8B><td height=25><center><a href=\"showBulletin.php?id=".$array['id']."\" class=\"nav\">Subject: ".$array['subject']."</a></center>"; echo "</td></tr></table><br><br>"; } }}?>[/code]you have 1 too many } but i layed it out incase that is the ending of another statementRegardsLiam Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted September 24, 2006 Author Share Posted September 24, 2006 mmm didn't seem to work.. the same things happens as with my code Quote Link to comment Share on other sites More sharing options...
alpine Posted September 24, 2006 Share Posted September 24, 2006 use mysql_num_rows[code]<?php$user = $_SESSION[username];$queryF="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";$resultF=mysql_query($queryF);if(mysql_num_rows($resultF)=="0"){ echo "No Bulletins. Tell your friends to post some!!";}else{while($array=mysql_fetch_assoc($resultF)){$poster=$array[friend];$queryB="SELECT * FROM `bulletins` WHERE `from` = '$poster' ORDER by 'id' DESC";$resultB=mysql_query($queryB);while($array=mysql_fetch_assoc($resultB)){echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#548099><td height=28><b><font color=white>From: <a href='getInfo.php?user=" . $array['from'] . "' class='hidden'>" . $array['from'] . "</a></b><br><b>Date: </b>" .$array['date']; echo "</b></font></td></tr></table>"; echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#356B8B><td height=25><center><a href=\"showBulletin.php?id=".$array['id']."\" class=\"nav\">Subject: ".$array['subject']."</a></center>"; echo "</td></tr></table><br><br>";}}}?>[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted September 24, 2006 Author Share Posted September 24, 2006 thanks everyone for your help!! i got it! alpine:: i had to modify your code, bcuz you had the if(mysql_num_rows...) thing in the wrong place. you had it checking if you had no friends :-) no problem, I jsut moved it downa few lines and changed it from resultF to resultB -- well except now,, it says this exact thing: "No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!No Bulletins. Tell your friends to post some!!"why does it show it more than once?? i want it to display only one time Quote Link to comment Share on other sites More sharing options...
alpine Posted September 24, 2006 Share Posted September 24, 2006 Then you have mysql_num_rows inside your while, move it outside - or post some code so we can see Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.