FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Private Message count not going down?





Diablosblizz
Alright, this is sort of hard to explain, and I bet it's a simple fix, but here is my problem.

In my user system, where visitors can login, I have a private message feature. When you receive a message, it shows how many unread messages you have on the side (where the navigation for the user system is). My problem is that when you go to read the message, it sets the status (being read - 0 - or unread - 1). My problem is that when I go to read the message, and it sets the status to 1 (being read) it still shows that I have one unread message on the navigation for the user system. When I refresh the page, it then shows it as unread on the side. Here is my code for changing the status (pmc.php):

Code:

$id = $_GET['id'];
$update = mysql_query("UPDATE `privatem` SET `status` = '1' WHERE `id` = '$id'");


And to show the unread:

Code:

$privatemessages = mysql_query("SELECT * FROM `privatem` WHERE `to` = '$username' AND `status` = '0'");
$pm = mysql_num_rows($privatemessages);
echo "Inbox ($pm)";


How can I make it set the status to 1 before it reads the message, so when I am reading the message it won't show the message being read as unread on the side of my navigation?

I was thinking of doing a onclick on the href when I go to read the message, but I am not sure how I would do that without using Javascript.

Thanks and Kind Regards!
alalex
That is probably because the read/unread processing takes place after the navigation has loaded, so that even if you changed the status it won't show up until you refresh the page.
It is quite easy to solve it, simply put the code that changes the status from unread to read before the navigation, preferably on top of any html output, and this way when it gets to the navigation you have already changed the status.
Diablosblizz
There is one problem with that though. I am using the switch function, and I have a template pre-loaded function that loads it all for me (so it doesn't waste so much room for coding). The loading of the template also allows me to change my template quickly and easily.
DjMilez
Off topic a bit, but you are using the RMB user system right?

I could not get that to work D:
Diablosblizz
No I am not. I have in the past, but back then I was setting the template on every page.
alalex
Well if you can't alter the order in which the script loads then I can't tell you how to do it since I've never seen the templating system.

But the only way I see is to set the message to read before the actual navigation where the message count appears...

Maybe if you added the script to change the read/unread status where the navigation is... But as I said I can't say for sure without seeing the templating system Wink
Star Wars Fanatic
Is there any way you could put it in an outside function and call the function from within the switch, or where ever you need to, but before the navigation is outputted.

The only other thing I could see working, but would be really ugly and might not always work, is using Javascript to change it after the fact. But, like I said, that's really ugly and very inefficient.
Diablosblizz
Quote:
The only other thing I could see working, but would be really ugly and might not always work, is using Javascript to change it after the fact. But, like I said, that's really ugly and very inefficient.


See, I was thinking that too. Or, I could just use an <a href="blah" onclick="SOME PHP HERE IF I COULD">Blah</a>. But, I am not too sure if the PHP would work in the onclick.

Kind regards.
Star Wars Fanatic
Diablosblizz wrote:
Or, I could just use an <a href="blah" onclick="SOME PHP HERE IF I COULD">Blah</a>. But, I am not too sure if the PHP would work in the onclick.


Nope, that wouldn't work, as PHP is executed upon page loading, before actually. You go to view a PHP page, your browser sends a request to the server, the server runs the PHP, and sends the resulting html to your browser. You cannot run PHP on a page after the page is loaded. The only way to remotely do it is with AJAX, and even then, you are just requesting another page, with then goes through the above steps.
So, you can't have PHP executed with an onclick event, as the PHP code will have already run.
Diablosblizz
So your basically saying that the only way I could do it is to put the template on pmc.php?
Related topics
Yahoo shuts down private rooms
Creating an RPG bot in IRC (yes I wrote this)
The justification for war
Introduction
Urban Legends About the Iraq War
Private Message Notification
Are atheists more likely to be fellons?
Frih.net going down every once in awhile tonight...
Posting and You!
The Daily Guess A Number Game: Day 111
servers going down today?
Win 150 FriH$ - My Sound Teaser Competition.
eeek mines going down hill
Private message system "delete selected."
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.