Jump to content

[SOLVED] messaging system


timmah1

Recommended Posts

I have 2 different databases, one named 'messages' and one named 'attack_log'

 

both databases have the same fields in them

If there is a message to somebody in either of the database with a status of 0, i need an icon to blink, and if there is no message or status of 1, i need a different icon to show

 

the problem is, no matter how i do this, it either shows a regular icon and a blinking icon, or none at all.

 

can anybody help me out with this?

 

$new3 = "(SELECT * FROM messages WHERE message_to = '"  .$_SESSION['SESS_USERNAME']. "') UNION ALL (SELECT * FROM attack_log WHERE message_to = '"  .$_SESSION['SESS_USERNAME']. "')";
$result3 = mysql_query($new3);
$numberall = mysql_num_rows($result3);

if($numberall == 0){
echo "<a href='messages.php'><img src='img/mail.png' height='25' title='check your mail and attack logs' alt='check your mail and attack logs' border='0' /></a>"; 
}

$row3 = mysql_fetch_array($result3);
if($row3['status'] == 0){
echo "<a href='messages.php'><img src='img/mail.gif' height='25' title='check your mail and attack logs' alt='check your mail and attack logs' border='0' /></a>"; 
}
else {
echo "<a href='messages.php'><img src='img/mail.png' height='25' title='check your mail and attack logs' alt='check your mail and attack logs' border='0' /></a>"; 
}

 

thanks in advance

Link to comment
Share on other sites

If you want to UNION your queries, you'll need to have each query return a count (which is more efficient anyway):

 

$sql = "(SELECT COUNT(*) FROM messages WHERE message_to='".$_SESSION['SESS_USERNAME']."') UNION ALL (SELECT COUNT(*) FROM attack_log WHERE message_to='".$_SESSION['SESS_USERNAME']."')"
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$count1 = mysql_result($result,0);
$count2 = mysql_result($result,1);
if($count1 == 0 && $count2 == 0){
    //no rows in either
}else{
    //rows in one or the other
}

 

Of course, i would question your database structure if you have two tables with the same fields in them...

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.