Tutorials and programming - Anyone know how to modify this?

starteck2002 - Aug 29, 2005 - 10:03 PM
Post subject: Anyone know how to modify this?
Code:
// make sure the user is logged in
if (pnUserloggedin()){
// pre .750 connection
// list($dbconn) = pnDBGetConn();
////////////////////////////////////////
// 750+ connection
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
////////////////////////////////////////
$pntable = pnDBGetTables();
$column = &$pntable['priv_msgs_column'];
$result = $dbconn->Execute("SELECT count(*) FROM $pntable[priv_msgs] WHERE $column[read_msg] ='0' and $column[to_userid]='".pnUserGetVar('uid')."'");
list($unread) = $result->fields;
if($unread >=1){ 
echo '<img src="path/to/flashing/image.gif" />';
 }
}


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 Sad

Anyone have any ideas?

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

TIA, Dave
Chestnut - Aug 29, 2005 - 10:19 PM
Post subject: Re: Anyone know how to modify this?
Little clean up first
Code:

// make sure the user is logged in
if (pnUserloggedin()) {

    // if code must look in a 3rd party, make sure the module tables are loaded

    // pnModDBInfoLoad('pmBOX');

    $dbconn  =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    $tbl    = $pntable['priv_msgs'];
    $column = &$pntable['priv_msgs_column'];
   
    $result = $dbconn->Execute("SELECT count(*)
                                FROM   $tbl
                                WHERE  $column[read_msg]  = '0'
                                AND    $column[to_userid] = '".pnUserGetVar('uid')."'");
                               
    list($unread) = $result->fields;
   
    if($unread >=1){
        echo '<img src="path/to/flashing/image.gif" />';
    }
   
}


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

Code:

    $tbl    = $pntable['priv_msgs'];


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
starteck2002 - Aug 29, 2005 - 11:23 PM
Post subject:
I must be doing something wronmg Sad

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 Smile



Image

Code:
// make sure the user is logged in
if (pnUserloggedin()) {

    // if code must look in a 3rd party, make sure the module tables are loaded

    pnModDBInfoLoad('pmBOX');

    $dbconn  =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    $tbl    = $pntable['pn_messenger'];
    $column = &$pntable['pn_read_msg'];
   
    $result = $dbconn->Execute("SELECT count(*)
                                FROM   $tbl
                                WHERE  $column[read_msg]  = '0'
                                AND    $column[to_userid] = '".pnUserGetVar('uid')."'");
                               
    list($unread) = $result->fields;
   
    if($unread >=1){
        echo '<img src="path/to/flashing/image.gif" />';
        echo 'Unread Messages:'+'$unread';
    }
   
}

Chestnut - Aug 30, 2005 - 12:06 AM
Post subject:
Variables are not parsed between single quotes :

Code:

    if($unread >=1){
        echo '<img src="path/to/flashing/image.gif" />';
    }
    echo 'Unread Messages: '.$unread;


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

Code:

    $result = $dbconn->Execute("SELECT count(*)
                                FROM   $tbl
                                WHERE  $column[read_msg]  = '0'
                                AND    $column[to_userid] = '".pnUserGetVar('uid')."'");

    if ($dbconn->ErrorNo() != 0) {
        echo $dbconn->ErrorMsg();
    }


As for the rest................ Question

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 - Aug 30, 2005 - 12:09 AM
Post subject:
aw dammit.......

Code:

    $tbl    = $pntable['pn_messenger'];
    $column = &$pntable['pn_read_msg'];



SIGH !!!! SO WRONG !!!!!!! Laughing

Should be :

Code:

    $tbl    = &$pntable['messenger'];
    $column = &$pntable['messenger_column'];

starteck2002 - Aug 30, 2005 - 09:32 AM
Post subject:
yes, there is at least one unread message 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 Sad

Anyone heard any news about Alex (PortalZine)? Hope he's ok.
starteck2002 - Aug 30, 2005 - 12:32 PM
Post subject:
Code:

// make sure the user is logged in
if (pnUserloggedin()) {

    // if code must look in a 3rd party, make sure the module tables are loaded

    pnModDBInfoLoad('Messenger');

    $dbconn  =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    $tbl    = $pntable['messenger'];
    $column = &$pntable['messenger_column'];
   
    $result = $dbconn->Execute("SELECT count(*)
                                FROM   $tbl
                                WHERE  $column[read_msg]  = '0'
                                AND    $column[to_userid] = '".pnUserGetVar('uid')."'");
                               
   

// if ($dbconn->ErrorNo() != 0) {
//        echo $dbconn->ErrorMsg();
//    }

     list($unread) = $result->fields;
   
    if($unread >=1){
        echo '<img src="path/to/flashing/image.gif" />';
         
    }
  echo 'Unread Messages: '.$unread; 
}


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 - Aug 30, 2005 - 01:25 PM
Post subject:
mmm... I don't see much...

The where is there.
All times are GMT + 1 Hour
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits