Jump to content

Archived

This topic is now archived and is closed to further replies.

techiefreak05

if query returns 0 .. how to ??

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 statement

Regards
Liam

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Then you have mysql_num_rows inside your while, move it outside - or post some code so we can see

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.