Welcome Guest [Log In] [Register]
Add Reply
php message notification
Topic Started: Apr 23 2009, 09:23 AM (1,953 Views)
Knight13

0
Edited by Knight13, Mar 19 2010, 07:02 AM.
Offline Profile Quote Post Goto Top
 
cyrus709

sure, I have not used this idea yet, and have not even really thought of the idea until i read this.

Depends really on how you set it up, but i guess you could add a row name "read" . Then when someone sends a message it takes the user it sends it to, in a variable and updates that row WHERE would be the read statement and it would update it saying "NO". If it says "NO" there are two ways you could do this, you could simply write IF ($var== "NO") { print "<img scr="youhaveanewmailimage.png">}; you could make this display an image next to the inbox and when that image apears that know that they have a new message, and then when they click on the mail you would have it UPDATE the row saying "yes"

Ill write an example code, and if you need help post some code and ill see what i can do. Try making a text based game, you get very creative.


The other way, which you might prefer is after you have got the value "yes" or "no" you can transfer that to a JS (javascript) variable
and then make an alert when they sign on If the value is "yes", this way they have no choice but know that they have a new message (mail) il give an example of that also,

[ MERGED DOUBLE POST ]

Alright so here is the example, for the php, as im sure you can manage adding the column on your own.
Code:
 
<?php
//I assume your password protected? and if your useing cookies just swap out $_SESSION
$convert= $_SESSION['username'];
//$C is the connection variable
$C = mysql_connect("hostname","username","password");
if(!$C)
{
die('could not connect');
}
//Selects the DB
mysql_select_db("DB_NAME", $C);
////////Get the information from DB
$result = mysql_query("SELECT * FROM tablename
WHERE username='$convert'");
while($row = mysql_fetch_array($result))
{
$check= $row['read'];
if($check== 'no')
{
print "<img src="yourimagegoeshere.gif>";
}
else
{
die();
}
}
?>


You would put this code where you need it, like next to your inbox, you would also need to make sure that you set the defualt value in mysql to either "no" or yes so that it effects all rows that already exist.

Then when someone clicks on their mail this would be one of the first things that you put on your page, after your sessions.
Code:
 

<?
$convert= $_SESSION['username'];
//$C is the connection variable
$C = mysql_connect("hostname","username","password");
if(!$C)
{
die('could not connect');
}
//Selects the DB
mysql_select_db("DB_NAME", $C);
///sets the information
$result = mysql_query("SELECT * FROM tablename
WHERE username='$convert'");
while($row = mysql_fetch_array($result))
{
$check= $row['read'];
mysql_query("UPDATE tablename SET read = 'yes' WHERE username = '$convert'");

}
?>


Now thats all you have to do, but another option would be to convert it into JS. This would make it so that you get an alert after you log on. The second bit of code that i posted would still stay the same
Code:
 

<?php
//I assume your password protected? and if your useing cookies just swap out $_SESSION
$convert= $_SESSION['username'];
//$C is the connection variable
$C = mysql_connect("hostname","username","password");
if(!$C)
{
die('could not connect');
}
//Selects the DB
mysql_select_db("DB_NAME", $C);
////////Get the information from DB
$result = mysql_query("SELECT * FROM tablename
WHERE username='$convert'");
while($row = mysql_fetch_array($result))
{
$check= $row['read'];
}
?>
<script type="text/javascript">
var check = <?= $check ?>;
if($check === 'no')
{
alert ("You have an unread message");
}
else
{
document.write ("");
}
</script>


i hope this kind of helps, it helps me anyways :P if i ever need to do this, this will be how i do it. If this does not clear it up post what your table looks like and ill help you out. But im going on vacation for ten days tommorrow so it might have to wait, hope this helps ;)

and another thought popped into my head you could also have it so that it does both (which might be exsessive) you could also make it so that it plays an mp3 saying "you have mail", along with the mail button idk thats stuff that you could play around with to tweak it to make it cool. Now i want to make one
Edited by cyrus709, Apr 23 2009, 04:12 PM.
Therapy is expensive, poppin' bubble wrap is cheap! You choose.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Web-Based Programming Support · Next Topic »
Add Reply

Banner and Logo by TheKeith