Jump to content


Photo

if query returns 0 .. how to ??


  • Please log in to reply
5 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 24 September 2006 - 07:33 AM

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.

<?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>";
}
 }
}
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 24 September 2006 - 07:38 AM

this should work

<?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>";
  }
 }
}
?>

you have 1 too many } but i layed it out incase that is the ending of another statement

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 24 September 2006 - 07:46 AM

mmm didn't seem to work.. the same things happens as with my code
Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 07:51 AM

use mysql_num_rows
<?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>";
}
}
}
?>


#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 24 September 2006 - 07:59 AM

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 shortener with advanced, detailed statistics:

http://tyny.us/

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 08:14 AM

Then you have mysql_num_rows inside your while, move it outside - or post some code so we can see




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users