Page 1 of 1

Messaging system

Posted: Tue Sep 07, 2004 11:45 am
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

Posted: Tue Sep 07, 2004 12:00 pm
by feyd
your while loop only finds 1 row.. move the return call to after the while loop.

Posted: Tue Sep 07, 2004 12:01 pm
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.