View Single Post
Old 12-15-2012, 11:16 PM   PM User | #23
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 610
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Sorry, I had something come up and need to run out.


Quote:
Originally Posted by tangoforce View Post
Yes. Just remember in your SQL where clause don't just do where pmid='<the PMs ID>' also do a members user id too so that they can only delete their own messages - eg:

delete from messages where pmID='$pmID' and userID='$userID'
Yeah, I currently do that.



Quote:
Also, not sure if you do this but you're best off constructing one long SQL statement EG:

delete from messages where (pmID='52' or pmID='51' or pmID='50') and userId='$userID'

That will let you do the entire thing in one SQL query rather than 30 or 40 seperate queries. To make it (very basic - you'll need to do your own checks)...

PHP Code:
foreach ($_POST['testArray'] as $Key => $Value)
   {
   
$Array[] = "pmID='$Value'";
   }

$IDs implode(' or '$Array); // "pmID='52' or pmID='51' or pmID='50'"

$SQL "delete from messages where ($IDs) and userId='$userID'" 
Again you'll need to change that for prepared statements but it should point you in the right direction.
Well, on that one I want to keep what I have because I am unit testing, and unless there is a *major* issue, no more code changes are allowed!!

Here is what I currently have...
PHP Code:
    // ************************
    // Mark Delete as Purge.    *
    // ************************
    
foreach($_POST['msgArray'] as $msgID => $msgValue){


        
// **************************
        // Determine Message Type.    *
        // **************************

        // Build query.
        
$q15 "SELECT member_id,...

                WHERE pm.id =?
                LIMIT 1"
;


        
// Check # of Records Returned.
        
if (mysqli_stmt_num_rows($stmt15)==1){
            
// Message Found.


            // Incoming Message.
            
$q16 "UPDATE private_msg

                WHERE member_id=?
                AND message_id=?
                LIMIT 1"


So since I got side-tracked, and won't have a chance to soak in all of your great advice right now, I'm not entirely clear what to do with the Implode/Explode.

However, I do know this...

Just like above, I need a way to look through the listing of all Messages in the $_POST results set, and run an UPDATE query on each one. (I'm not sure if your suggestions will let me do that??)

I like your suggestion of "do it in all one query", but if I keep improving my code, I won't be done with this latest release until 2015!!!!!!!!!

Let's hope that we talked about enough of my coding issues that I can piece together a solution later tonight or tomorrow?!

Thanks,


Debbie
doubledee is offline   Reply With Quote