View Single Post
Old 01-05-2013, 04:23 AM   PM User | #5
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 612
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by Fou-Lu View Post
For this you need to describe empty in your definition of it. From what I gather, you do not consider a space delimited string to be empty (and nor should you as it is not empty), so you would use the empty() function for that. Empty is true so long as the item it is given equates to false, so that will be false, 0, 0.0, "", "0", array(), null and uninstantiated object properties.
Assuming that 0 is never valid and you cannot possibly end up with spaces than empty is sufficient. Or you can never convert it to a string and retain it as an array and use the empty or count on the array instead. Arrays are far more useful than a string anyways.
I'm not following you.

In my HTML section, I have this code, which populates the selectedMsgArray with an entry for each Private Message that is checked...

PHP Code:
    // Loop through Messages.
    
while (mysqli_stmt_fetch($stmt6)){
        echo 
"<tr" . (is_null($readOn) ? " class='pmUnread'" "") . ">
                <td class='colSelect'>
                    <input id='"
                    
str2htmlentities($pmID)
                    . 
"' name=selectedMsgArray["
                    
str2htmlentities($pmID)
                    . 
"] type='checkbox' value=1 />
                </td> 

Then at the top of my script - in the section handles the submitted Form - I have this snippet...

PHP Code:
    // **************************
    // Mark Incoming as Unread.    *
    // **************************
    
if (!empty($_POST['selectAll']) && $_POST['selectAll'] == 1){
        
// All Messages Selected.
        
echo "All Messages Selected<br />";

        
$messagesToUpdate implode(', 'array_keys($_POST['msgArray']));

    }elseif (!empty(
$_POST['selectedMsgArray']) && $_POST['selectedMsgArray']){
        
// Some Messages Selected.
        
echo "Some Messages Selected<br />";

        
$messagesToUpdate implode(', 'array_keys($_POST['selectedMsgArray']));

    }else{
        
// No Messages Selected.
        
echo "No Messages Selected<br />";

        
$messagesToUpdate '';

    }
//End of MARK INCOMING AS UNREAD

    
echo '$messagesToUpdate = ' $messagesToUpdate;


    if (isset(
$messagesToUpdate) && $messagesToUpdate){
//            if (!empty($messagesToUpdate)){
        // Update Selected Messages.

        // Build query.
        
$q1 "UPDATE private_msg_recipient...

    }else{
        // Do nothing.

    } 
If the User never checked any PM's, then $messagesToUpdate = '' and I do NOT want my UPDATE query to run.

Above you can see the code I commented out, and what I have now, which seems to make sense.

Follow me?


Debbie
doubledee is offline   Reply With Quote