Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

script not working...

Recommended Posts

Hey,
I have a PM system and wanted to alert any user if they receive a new PM whilst somewhere else on the site. I attached my code into the sessions which is on every page it doesn't work.

I had a new Pm and it wouldn't alert me:
[code=php:0]include "db.php";
$ssql = mysql_query("SELECT * FROM pm WHERE sendto='{$_SESSION['user']['user']}' AND stats='0'");
$numb = @mysql_num_rows($ssql);
if( $numb > 0 )
{
echo '<script>alert("You have got a new Private message")</script>';
}[/code]

Share this post


Link to post
Share on other sites
You could try something like...
$query = "SELECT COUNT(*) FROM pm WHERE sendto='{$_SESSION['user']['user']}' AND stats='0'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
    echo '<script>alert("You have got a new Private message")</script>';
}

Question: Why do you have $_SESSION['user']['user']? Why don't you use use $_SESSION['user']?

And, some people disable javascript so your alert wouldn't do anything anyways.

You can put <noscript> tags around an alternate message for people who turn it off. That way, they would be notified even if they have javascript turned off.

Share this post


Link to post
Share on other sites
What would <noscript> do? and how would I do this?

Share this post


Link to post
Share on other sites
[url=http://www.w3schools.com/tags/tag_noscript.asp]The <noscript> tag[/url]

Orio.

Share this post


Link to post
Share on other sites

×

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.