Messaging system

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Getran
Forum Commoner
Posts: 59
Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:

Messaging system

Post by Getran »

Hey, i'm trying to make a messaging system for my users, and all works fine except my script is only displaying one row from the DB.

i put it into a functioin called getMessages(), here's the function:

Code: Select all

function getMessages() {
  mysql_connect("localhost","****","****");
  mysql_select_db("****");
  $player = $_SESSIONї'charactername'];
  $sql = "SELECT * FROM messages WHERE `receiver`='$player'";
  $grabem = mysql_query($sql) or die(mysql_error());
  while($fields=mysql_fetch_array($grabem))
  {
    $date=$fieldsї'date'];
    $id=$fieldsї'message_id'];
    $sender_name=$fieldsї'sender_name'];
    $subject=$fieldsї'subject'];
    $sender_id=$fieldsї'sender_id'];
    $player_id=$fieldsї'player_id'];
    $message=$fieldsї'message'];

    $display = "   ".$date."<br>";
    $display .= "   From: ".$sender_name."(".$sender_id.")";
    $display .= "<br>";
    $display .= "   Subject: ".$subject;
    $display .= "<br>";
    $display .= "   ".$message;
    $display .= "<br><center><a href='game.php?page=reply&name=".$sender_name."&id=".$sender_id."'>Reply</a>";
    $display .= "  |  <a href='process.php?action=delete_message&id=".$id."'>Delete</a>";
    $display .= "<hr></center>";
    return $display;
  }
}
Is there something wrong with the function ? cus i thought that by using a while loop it grabs all of the rows .. ?

Any help is appreciated...

*EDIT* I just tried the script out of the function, and it works ok...how can i make it work within the function ?? or will i just have to scrap it ? lol
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your while loop only finds 1 row.. move the return call to after the while loop.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

did you try to execute "SELECT * FROM messages WHERE `receiver`='$player'" directly into de DB... for example using phpmyAmdin o mysql control center.
Post Reply