Jump to content

if query returns 0 .. how to ??


techiefreak05

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.