Jump to content

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


techiefreak05

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....
Link to comment
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.
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.