Jump to content


Photo

MySQL Query inside another MySQL While Loop .. need some HELP!!


  • Please log in to reply
3 replies to this topic

#1 techiefreak05

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

Posted 11 September 2006 - 04:38 AM

i have a code that gets all your friends from the "friends": table... and then takes that info and gets all the bulletins from the "bulletins" table and then shows all the bulletins posted by all your friends... .. but its not working.. no error.. its just the bulletins are not showing up ...

<?php
$query="SELECT * FROM friends WHERE `username` = '$_SESSION[username]' AND `accepted` = 'yes'";
$result=mysql_query($query);
while($array=mysql_fetch_assoc($result)){
$poster = $array['friend'];

$user = $_SESSION[username];

if(!isset($_GET['bulletinPage'])){ 
    $Bpage = 1; 
} else { 
    $Bpage = $_GET['bulletinPage']; 
} 

$max_results = 5; 


$from = (($Bpage * $max_results) - $max_results); 

$query="SELECT * FROM `bulletins` WHERE `from` = '$poster' ORDER by 'id' DESC LIMIT $from, $max_results";

$result=mysql_query($query);

while($array=mysql_fetch_assoc($result)){

echo "<table bgcolor=#99CCFF width=200><tr bgcolor=#548099><td height=28><b><font color=white>From: <a href='getInfo.php?user=" . $array['from'] . "'>" . $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']."\">Subject:  ".$array['subject']."</a></center>";
  echo "</td></tr></table><hr>";
 }
}

some of the code in there is the pagination code....
Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 11 September 2006 - 08:03 AM

It's good practice to check mysql_query() for errors.

$result = mysql_query($query);
if ($result === false) die("Mysql error: " . mysql_error() " on query $query\n");

If that doesn't work, then print out your queries before executing them.  It's likely there's a problem with one of them.

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 11 September 2006 - 08:39 AM

Where do you start the session, and where do you check that $_SESSION['username'] has a value?

Also, learn to use JOIN's and not nested mysql_query()'s.

#4 techiefreak05

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

Posted 11 September 2006 - 10:02 PM

the answer to both ur questions::
earlier in the code
Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users