Topic: Anyone know how to modify this?
starteck2002
avatar
Noob
Noob
Posts: 4

Posted:
Aug 29, 2005

Code
  1. // make sure the user is logged in
  2. if (pnUserloggedin()){
  3. // pre .750 connection
  4. // list($dbconn) = pnDBGetConn();
  5. ////////////////////////////////////////
  6. // 750+ connection
  7. $dbconn =& pnDBGetConn(true);
  8. $pntable =& pnDBGetTables();
  9. ////////////////////////////////////////
  10. $pntable = pnDBGetTables();
  11. $column = &$pntable['priv_msgs_column'];
  12. $result = $dbconn->Execute("SELECT count(*) FROM $pntable[priv_msgs] WHERE $column[read_msg] ='0' and $column[to_userid]='".pnUserGetVar('uid')."'");
  13. list($unread) = $result->fields;
  14. if($unread >=1){ 
  15. echo '<img src="path/to/flashing/image.gif" />';
  16.  &#125;
  17. &#125;
  18.  


This bit of code will display a gif image if there is any unread PM's. I purchased PMBOX Messenger from PortalZine and this code does not work for that (looks at wrong tables). Alex (of PortalZine) has not been around for a while due to illness so I can't ask him and to add to that he has encoded his block with ioncube so i can't look at that either icon_frown

Anyone have any ideas?

I can give full access to my site for anyone who is interested in getting this working.

TIA, Dave
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Aug 29, 2005

Little clean up first
Code
  1. // make sure the user is logged in
  2. if &#40;pnUserloggedin()) {
  3.  
  4.     // if code must look in a 3rd party, make sure the module tables are loaded
  5.  
  6.     // pnModDBInfoLoad('pmBOX');
  7.  
  8.     $dbconn  =& pnDBGetConn&#40;true);
  9.     $pntable =& pnDBGetTables&#40;);
  10.  
  11.     $tbl    = $pntable&#91;'priv_msgs'];
  12.     $column = &$pntable&#91;'priv_msgs_column'];
  13.    
  14.     $result = $dbconn->Execute&#40;"SELECT count(*)
  15.                                 FROM   $tbl
  16.                                 WHERE  $column&#91;read_msg]  = '0'
  17.                                 AND    $column&#91;to_userid] = '".pnUserGetVar('uid')."'");
  18.                                
  19.     list&#40;$unread) = $result->fields;
  20.    
  21.     if&#40;$unread >=1){
  22.         echo '<img src="path/to/flashing/image.gif" />';
  23.     &#125;
  24.    
  25. &#125;
  26.  


Now I modified the table call to give you a more easy way to change the table the code must look in :

Code
  1. $tbl    = $pntable&#91;'priv_msgs'];
  2.  


And I added the pnModDBInfoLoad that you will probably need if you are getting the tables of the pmBOX instead of the original ones. Just remove the // in front of it.

Lastly, remember to change the "pathto/flashing/image....."
:wink:

Chestnut ! Cool
Site Admin
starteck2002
avatar
Noob
Noob
Posts: 4

Posted:
Aug 30, 2005

I must be doing something wronmg icon_frown

I've changed the tables, added a bit to show the number of messages as well as the graphic but it's still not working. I've attached a screen grab of the DB. I suppose it might help if I actually understood what I was doing. Thanks very much for your help so far Frank icon_smile





Code
  1. // make sure the user is logged in
  2. if &#40;pnUserloggedin()) {
  3.  
  4.     // if code must look in a 3rd party, make sure the module tables are loaded
  5.  
  6.     pnModDBInfoLoad&#40;'pmBOX');
  7.  
  8.     $dbconn  =& pnDBGetConn&#40;true);
  9.     $pntable =& pnDBGetTables&#40;);
  10.  
  11.     $tbl    = $pntable&#91;'pn_messenger'];
  12.     $column = &$pntable&#91;'pn_read_msg'];
  13.    
  14.     $result = $dbconn->Execute&#40;"SELECT count(*)
  15.                                 FROM   $tbl
  16.                                 WHERE  $column&#91;read_msg]  = '0'
  17.                                 AND    $column&#91;to_userid] = '".pnUserGetVar('uid')."'");
  18.                                
  19.     list&#40;$unread) = $result->fields;
  20.    
  21.     if&#40;$unread >=1){
  22.         echo '<img src="path/to/flashing/image.gif" />';
  23.         echo 'Unread Messages:'+'$unread';
  24.     &#125;
  25.    
  26. &#125;
  27.  
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Aug 30, 2005

Variables are not parsed between single quotes :

Code
  1. if&#40;$unread >=1){
  2.         echo '<img src="path/to/flashing/image.gif" />';
  3.     &#125;
  4.     echo 'Unread Messages: '.$unread;


And lastly, it is better to check if you have an sql error...

Code
  1. $result = $dbconn->Execute&#40;"SELECT count(*)
  2.                                 FROM   $tbl
  3.                                 WHERE  $column&#91;read_msg]  = '0'
  4.                                 AND    $column&#91;to_userid] = '".pnUserGetVar('uid')."'");
  5.  
  6.     if &#40;$dbconn->ErrorNo() != 0) {
  7.         echo $dbconn->ErrorMsg&#40;);
  8.     &#125;
  9.  


As for the rest................ :?:

By the way... only to put that question away... I hope for you that you have at least 1 unread message because if not... :wink:

Chestnut ! Cool
Site Admin
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Aug 30, 2005

aw dammit.......

Code
  1. $tbl    = $pntable&#91;'pn_messenger'];
  2.     $column = &$pntable&#91;'pn_read_msg'];
  3.  



SIGH !!!! SO WRONG !!!!!!! icon_lol

Should be :

Code
  1. $tbl    = &$pntable&#91;'messenger'];
  2.     $column = &$pntable&#91;'messenger_column'];
  3.  


Chestnut ! Cool
Site Admin
starteck2002
avatar
Noob
Noob
Posts: 4

Posted:
Aug 30, 2005

yes, there is at least one unread message icon_wink

I'll give this a go tonight and see if it works. This is all because I designed a theme and it requires the number of unread pm's to be displayed - i thought it was a really easy task icon_frown

Anyone heard any news about Alex (PortalZine)? Hope he's ok.
starteck2002
avatar
Noob
Noob
Posts: 4

Posted:
Aug 30, 2005

Code
  1. // make sure the user is logged in
  2. if &#40;pnUserloggedin()) {
  3.  
  4.     // if code must look in a 3rd party, make sure the module tables are loaded
  5.  
  6.     pnModDBInfoLoad&#40;'Messenger');
  7.  
  8.     $dbconn  =& pnDBGetConn&#40;true);
  9.     $pntable =& pnDBGetTables&#40;);
  10.  
  11.     $tbl    = $pntable&#91;'messenger'];
  12.     $column = &$pntable&#91;'messenger_column'];
  13.    
  14.     $result = $dbconn->Execute&#40;"SELECT count(*)
  15.                                 FROM   $tbl
  16.                                 WHERE  $column&#91;read_msg]  = '0'
  17.                                 AND    $column&#91;to_userid] = '".pnUserGetVar('uid')."'");
  18.                                
  19.    
  20.  
  21. // if ($dbconn->ErrorNo() != 0) {
  22. //        echo $dbconn->ErrorMsg();
  23. //    }
  24.  
  25.      list&#40;$unread) = $result->fields;
  26.    
  27.     if&#40;$unread >=1){
  28.         echo '<img src="path/to/flashing/image.gif" />';
  29.          
  30.     &#125;
  31.   echo 'Unread Messages: '.$unread
  32. &#125;
  33.  


This is now working but shows all messages, not just unread messages. Any ideas on what to do next?

Thanks for your help,

Dave

EDIT : Code tag, code tag, code tag, code tag....
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Aug 30, 2005

mmm... I don't see much...

The where is there.


Chestnut ! Cool
Site Admin