Jump to content

Pm system help


stelthius

Recommended Posts

Ok guys sorry to bother you, but i dfo have a slight situation.

basicly when i try to show on a users profile they have new messeges it shows everyone as having new messeges, and i cant quite figure it out

 

 

Here is my code below

 

 

<?
//Are they logged in or not?
if($session->logged_in){
?>
<?
$result = mysql_query("SELECT unread FROM messages");
$num_rows = mysql_num_rows($result);
?>
you have <a href="inbox.php"><? echo $num_rows; ?> new</a> messeges
<?
}
else
{
?>
<br>Please login to use the PM System.
<?
}
?>

 

Regards Rick

Link to comment
Share on other sites

and if i change my sql query to

 

$num = mysql_query("SELECT * FROM messages WHERE unread = 'unread' and touser = '$session->username'");
$num = mysql_num_rows($num);

 

It doesnt show that a user has x amount of new messeges and yes im also altering my <? echo $num_rows; ?> to <? echo '$num'; ?> but i just cant seem to get it to work right for me.

 

regards Rick

Link to comment
Share on other sites

Yes that snippet dioes but it doesnt show how many unread messeges they have this is were im struggling i've tried using

 

<?
//Are they logged in or not?
if($session->logged_in){
?>
<?
$result = mysql_query("SELECT unread FROM messages");
$num_rows = mysql_num_rows($result);
?>
you have <a href="inbox.php"><? echo $num_rows; ?> new</a> messeges
<?
}
else
{
?>
<br>Please login to use the PM System.
<?
}
?>

 

then you have Hello (username) you have <? echo $num_rows; ?> new messages

messages is the name of the table the messages go and touser is the person it went to, that way, it will only show up in that persons page, but it isnt working out like that its telling me have X amount of new messages even though they are addressed to others.

 

And i have also tried doing it this way too

 

<?
//Are they logged in or not?
if($session->logged_in){
?>
<?
$num = mysql_query("SELECT * FROM messages WHERE unread = 'unread' and touser = '$session->username'");
$num = mysql_num_rows($num);
?>
you have <a href="inbox.php"><? echo '$num'; ?> new</a> messeges
<?
}
else
{
?>
<br>Please login to use the PM System.
<?
}
?>

 

and finally the second snippet only shows (you have $num new messeges) im not a php guru im just learning as i move forwards but as you can see im stuck as to which way to go from here, any help is greatly appretiated

Link to comment
Share on other sites

seems that only my first code worksbut it shows that all users have x amount of PM's when infact only user x has x amount of PM's im unsure how to resolve this usse either, my second attempt works also but it doesnt show you have x amount of pms it just displays you have pms im kinda lost now and im unsure were to turn next, can anyone advise on this please ?

 

 

Regards Rick

Link to comment
Share on other sites

thanks for your reply but it never made any difference :(

 

its still showing you have $num new messeges

 

thats supposed to display you have x new messages

 

You have to wrap the variable in double quotes, single quotes on an echo means not to display the contents of a variable.

 

$num = 5;
echo("$num"); // 5
echo('$num'); // $num

Link to comment
Share on other sites

this is the closest ive gotten it to working, but it still isnt showing the ammount of new pm's the user has

 

<?
include("../include/session.php");
include("../include/checkban.php");
//Are they logged in or not?
if($session->logged_in){

?>
<?
$result = mysql_query("SELECT COUNT (*) FROM messages WHERE unread = 'unread' and touser = '$session->username'");
$num_rows = mysql_num_rows($result);
?>
you have <a href="inbox.php"><? echo $num_rows; ?> new</a> messeges
<?
}
else
{
?>
<br>Please login to use the PM System.
<?
}
?>

 

 

Rick

Link to comment
Share on other sites

Have a table called "messages", something like this:

id (primary key)

fromid

toid

message (text)

dt (int)

read (enum - yes/no)

 

When a user sends a message to someone they all go in that table. read is default to "no".

 

When the page is built have a query like this to make the "new mail" bit:

SELECT COUNT(id) FROM messages WHERE to=myIDnumber AND read=no

 

When the user gos to their inbox and reads it your script simply sets the "read" to "yes".

 

Link to comment
Share on other sites

hello,

 

My taqble is set out like

 

  id 		int(11)   				No  	auto_increment               
  reciever 	varchar(25) 	latin1_swedish_ci  	No                 
  sender 	             varchar(25) 	latin1_swedish_ci  	No                 
  subject 	text 		latin1_swedish_ci  	No                 
  message 	longtext 	             latin1_swedish_ci  	No                 
  recieved 	enum('1', '0')         latin1_swedish_ci  	Yes 	0                
  unread 	             varchar(255) 	latin1_swedish_ci  	No 	unread   

 

I thought this was ok myself but it looks as thos this is what is giving me problems ?

 

Thanks Rick

Link to comment
Share on other sites

hello,

 

My taqble is set out like

 

  id 		int(11)   				No  	auto_increment               
  reciever 	varchar(25) 	latin1_swedish_ci  	No                 
  sender 	             varchar(25) 	latin1_swedish_ci  	No                 
  subject 	text 		latin1_swedish_ci  	No                 
  message 	longtext 	             latin1_swedish_ci  	No                 
  recieved 	enum('1', '0')         latin1_swedish_ci  	Yes 	0                
  unread 	             varchar(255) 	latin1_swedish_ci  	No 	unread   

 

I thought this was ok myself but it looks as thos this is what is giving me problems ?

 

Thanks Rick

 

Uh, that would make the problem that there is no field named touser which we're looking for in these scripts.  ;\

Link to comment
Share on other sites

Forgot to add - if the COUNT() query comes back higher than 0 then they have new mail - if it returns 0 then have no new mail.

 

Re. your table - there's no need to have "received" as far as I can see as it will either be in the table or it won't be.

 

Not sure why you've got unread as VARCHAR - I'd have it as an enum: 'yes','no'

 

bluesoul pointed the last bit out.

 

EDIT: I'm just loading cPanel now so I dump my inbox table and show it to you.

Link to comment
Share on other sites

Here's a dump of my table:

CREATE TABLE IF NOT EXISTS `inbox` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `toid` mediumint( unsigned NOT NULL default '0',
  `fromid` mediumint( unsigned NOT NULL default '0',
  `message` text NOT NULL,
  `dt` int(10) unsigned NOT NULL default '0',
  `read` enum('yes','no') NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Link to comment
Share on other sites

Ok sorry to keep this going but i have made my edits to the DB (sorry its been a long day again) lol

 

  
  id int(11)                                                                  No  auto_increment               
  reciever           varchar(25)                latin1_swedish_ci  No                 
  sender             varchar(25)                latin1_swedish_ci  No                 
  subject            text                          latin1_swedish_ci  No                 
  message          longtext                     latin1_swedish_ci  No                 
  unread            enum('yes', 'no')           latin1_swedish_ci  No                 
  touser            varchar(30)                 latin1_swedish_ci  No 

 

Ok so now with that done its actually now showing me i have 0 PM's on the account that has no new pm's but on the second account that has one new pm it is also showing as 0 PM's, ihave a feeling im missing something from the touser table in the DB but im unsure what exactly.

 

Regards Rick

Link to comment
Share on other sites

this is what checks if a user has new pm's this works in my pm system

 

$query = "SELECT id, sender, subject, message FROM messages WHERE reciever='$user'";
$sqlinbox = mysql_query($query)

 

my pm system fully works its just a small addon im trying to make that show if a user has new pm's or not on the index page of the site which i thought using my past poists would work but its proving difficult

Link to comment
Share on other sites

$query = "SELECT id, sender, subject, message FROM messages WHERE reciever='$user' AND unread='yes'";

 

That should do it.

 

BUT... I would actually change it to this:

$query = "SELECT COUNT(id) FROM messages WHERE reciever='$user' AND unread='yes'";

 

Then just check if the value returned is greater than 0 - if yes the user has new and unread mail.

Link to comment
Share on other sites

ok so you say that this should work

 

$query = "SELECT COUNT(*) FROM messages WHERE reciever='$user' AND unread='yes'";

 

 

but my reciever field in the DB is set out like this

reciever varchar(25) latin1_swedish_ci  No 

i think its incorrect is it ?

 

and lastly i edited my actualy trest code to show this

 

 

<?
include("../include/session.php");
include("../include/checkban.php");
//Are they logged in or not?
if($session->logged_in){

?>
<?
$query = "SELECT COUNT(*) FROM messages WHERE reciever='$user' AND unread='yes'";
$num = mysql_num_rows($num);
?>
you have <a href="inbox.php"><? echo "$num"; ?> new</a> messeges
<?
}
else
{
?>
<br>Please login to use the PM System.
<?
}
?>

 

but it just doesnt seem to be working, im sorry if im missing a simple error here but im still learning as i said earlier, also your help is appretiated too

 

Link to comment
Share on other sites

First, use the full <?php instead of <? - not all servers have <? enabled!

 

$query = "SELECT COUNT(id) FROM messages WHERE reciever='$user' AND unread='yes'";
$row=mysql_fetch_assoc(mysql_query($query));
if ($row['0']>0) {
  echo '<a href="inbox.php">You have mail!</a>';
}

 

Have that on every page and it'll show if the user has new mail. Then on your inbox script you can group the mail - those unread at the top followed by those read.

 

This is also valid:

$query = "SELECT id FROM messages WHERE reciever='$user' AND unread='yes'";
$num=mysql_num_rows($query);
if ($num>0) {
  echo '<a href="inbox.php">You have mail!</a>';
}

 

Link to comment
Share on other sites

Ok ive made the alterations you suggested but as i said earlier its not showing the amount of new pm's the user has

 

new code :

 

<?php

include("../include/session.php");

include("../include/checkban.php");

//Are they logged in or not?

if($session->logged_in){

 

?>

<?

$query = "SELECT COUNT(*) FROM messages WHERE reciever='$user' AND unread='yes'";

$num=mysql_num_rows($query);

if ($num>0) {

  echo 'You have mail!';

}

?>

you have <a href="inbox.php"><? echo "$num"; ?> new</a> messeges

<?

}

else

{

?>

<br>Please login to use the PM System.

<?

}

?>

 

and it is also showing the member with no pm's as having new pm's all it does show is you have new(new is linked to inbox) messeges

Link to comment
Share on other sites

<?php
  include("../include/session.php");
  include("../include/checkban.php");
//Are they logged in or not?
  if ($session->logged_in) {
    $query = "SELECT id FROM messages WHERE reciever='$user' AND unread='yes'";
    $num=mysql_num_rows($query);
    if ($num>0) {
      echo '<a href="inbox.php">You have '.$num.' new message(s)</a>'
    }
  } else {
    echo 'Please login to use the PM System.';
  }
?>

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.