Jump to content

Recommended Posts

Hi everyone.

 

I have a PMS for my users within my site.

I want to run a query that will detect that a specific user who are login to the site,

has how many new messages...

How to perfrom this query:

Like:

$sql = "select * from pms where to_id = '$nruser1' AND opened ='no' ";
$result = mysql_query($sql);
$row = mysql_num_rows($result);
Echo "You have $row new messages.";

 

 

Any help will appreciated.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/
Share on other sites

@ thorpe

PMS mean private messaging system just like the phpfreaks are using.

When some some body have new message from other member, when he go to his inbox there a

small line that "you have 2 new messages"

 

@fert

thanks for ur query i will try it.

Fert - Where did this come from?

$num=$row['num'];

 

I don't understand where you pulled $row['num'] from.

 

<?php

$sql = "select * from pms where to_id = '$nruser1' AND opened ='no' ";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

if ($num > 0){
   echo "You have $num new messages!";
}

?>

@ pocobueno1388...

 

Fert - Where did this come from?

$num=$row['num'];

 

I don't understand where you pulled $row['num'] from.

 

<?php

$sql = "select * from pms where to_id = '$nruser1' AND opened ='no' ";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

if ($num > 0){
   echo "You have $num new messages!";
}

?>

 

Thanks pocobueno1388...

So it means that ur query will echo if they new message if no new message then nothing

to show to the user...

OHHH

Yeh also this, my mind is dull this time:

if ($num > 0){
   echo "You have $num new messages!";
}esle
{ echo "You have 0 messages!";
}

 

I think this will work.

Am i right

 

@ fert

 

Thanks fert for ur correction.

 

I will try both, hope both will work.

 

Oh, I thought you just wanted to show <b>new</b> messages, take out this code:

 

if ($num > 0){
   echo "You have $num new messages!";
}esle
{ echo "You have 0 messages!";
}

 

and this should be your final:

<?php

$sql = "select * from pms where to_id = '$nruser1' AND opened ='no' ";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

echo "You have $num new messages!";

?>

 

 

Oh, I thought you just wanted to show <b>new</b> messages, take out this code:

 

if ($num > 0){
   echo "You have $num new messages!";
}esle
{ echo "You have 0 messages!";
}

 

and this should be your final:

<?php

$sql = "select * from pms where to_id = '$nruser1' AND opened ='no' ";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

echo "You have $num new messages!";

?>

 

 

 

I think ur final code is same to my 1st post query, which did not work.

Am i right...

Hmmm, I guess that is the same thing you did...I wonder why it isn't working. First of all, did any of the suggested methods work for you?

 

If nothing has worked yet, try adding this to your query result:

$num = mysql_num_rows($result)or die(mysql_error());

 

I couldn't think of a way it wouldn't work unless you just queried the database wrong.

Yes u r right i also wondered, when it does not work bcoz i am not so bad in php.

That query just return the total number of messages for that user who

is looged in .

For example if he has 5 messages that code will show him

"You have 5 new messages". And that time he has no new msg  in the db.

 

Other:

I did not test the other queries yet bcoz i am far from my pc.

I will try that may be that will work.

 

Ok i will post either it works or not.

Thanks again for ur help.

 

 

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.