Jump to content

Archived

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

techiefreak05

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

Recommended Posts

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 ...

[code]<?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>";
}
}[/code]

some of the code in there is the pagination code....

Share this post


Link to post
Share on other sites
It's good practice to check mysql_query() for errors.

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

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

Share this post


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

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.