Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts

    code doesn't return the expected data?

    Hi all

    anybody any idea why this code doesn't return the expected data?

    I get this:

    These are your list of duplicates:

    Duplicate Txn ID: 0

    Duplicate Email Addresses: 0

    Duplicate Txn ID: e

    Duplicate Email Addresses: e

    BUT I expect smthg like this

    These are your list of duplicates:

    Duplicate Txn ID: 12345678

    Duplicate Email Addresses: someemail@abc.com

    Duplicate Txn ID: 12345678

    Duplicate Email Addresses: someemail@abc.com



    PHP Code:
                $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'"
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                
                
    $num_rowsmysql_num_rows($result);
                
                   if(
    $num_rows !=0){
                            
    $duplicates=mysql_fetch_assoc($result);
                                
    $content="These are your list of duplicates:\n\n\n";
                    foreach(
    $duplicates as $duplicate){
                        
    $content .= "Duplicate Txn ID: " $duplicate['txn_id'] . "\n\n";
                        
    $content .= "Duplicate Email Addresses: " $duplicate['user_email'] . "\n\n";
                }
            
                    
    mail($notify_email,"Duplicates Found",$content);

                    } 
    LT
    Last edited by low tech; 12-06-2010 at 09:31 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi Matt F

    OK finally


    I got something --- after trial and a million errors

    LT
    Last edited by low tech; 12-06-2010 at 10:35 AM.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    This part of your code:

    Code:
                $num_rows= mysql_num_rows($result);
                
                   if($num_rows !=0){
                            $duplicates=mysql_fetch_assoc($result);
                                $content="These are your list of duplicates:\n\n\n";
                    foreach($duplicates as $duplicate){
                        $content .= "Duplicate Txn ID: " . $duplicate['txn_id'] . "\n\n";
                        $content .= "Duplicate Email Addresses: " . $duplicate['user_email'] . "\n\n";
                }
    should now be looking something like this then?

    Code:
                
    if (mysql_num_rows($result))
    {
        $content = 'This is your list of duplicates:'."\n\n\n";
    
        while ($duplicate = mysql_fetch_assoc($result))
        {
            $content .= 'Duplicate Txn ID: '.$duplicate['txn_id']."\n\n";
            $content .= 'Duplicate Email Address: '.$duplicate['user_email']."\n\n";
        }

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi MattF

    Not exactly --- but nearly I guess

    If I send (for test) one duplicate tnx_id and one duplicate user_email

    I get in my error mail --- each one ---- so I thought it's good.

    BUT IF I send just one duplicate eg txn_id

    I get that txn_id in my error email PLUS the user email that belongs to that row BUT is not a duplicate email (it just belongs to that row)--- not good hahahahhaha

    So I made progress after three days --- but i'm not there:-(

    and I can't see a way to JUST get only the duplicate(s) that I send and nothing else.



    PHP Code:
    if ($checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'" ){
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                

                                while (
    $row mysql_fetch_assoc($result)){
                                
    //echo $row["txn_id"];
                                   //echo $row["user_email"];
                                
                                
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n";
                                
    $content .= "Duplicate Email Addresses: " $row["user_email"] . "\n\n";
                                
                }
            
                   
    mail($notify_email,"Duplicates Found",$content);

                    } 
    LT

  • #6
    New Coder
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by low tech View Post
    Hi MattF

    Not exactly --- but nearly I guess

    If I send (for test) one duplicate tnx_id and one duplicate user_email

    I get in my error mail --- each one ---- so I thought it's good.

    BUT IF I send just one duplicate eg txn_id

    I get that txn_id in my error email PLUS the user email that belongs to that row BUT is not a duplicate email (it just belongs to that row)--- not good hahahahhaha

    So I made progress after three days --- but i'm not there:-(

    and I can't see a way to JUST get only the duplicate(s) that I send and nothing else.



    PHP Code:
    if ($checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'" ){
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                

                                while (
    $row mysql_fetch_assoc($result)){
                                
    //echo $row["txn_id"];
                                   //echo $row["user_email"];
                                
                                
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n";
                                
    $content .= "Duplicate Email Addresses: " $row["user_email"] . "\n\n";
                                
                }
            
                   
    mail($notify_email,"Duplicates Found",$content);

                    } 
    LT
    Does the txn_id not auto-increment ?

    If your looking for duplicates with both email address and txn_id the same, then you need to change the OR in your query to AND.

    Something like:
    PHP Code:
    if ($checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'" ){
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                

                                while (
    $row mysql_fetch_assoc($result)){
                                
    //echo $row["txn_id"];
                                   //echo $row["user_email"];
                                
                                
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n";
                                
    $content .= "Duplicate Email Addresses: " $row["user_email"] . "\n\n";
                                
                }
            
                   
    mail($notify_email,"Duplicates Found",$content);

                    } 

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Compare the output against your original vars. id and e-mail within if blocks.

    Code:
    if ($row["user_email"] == $user_email)
    Same for the id.

  • #8
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi MattF

    yes I like yr idea for comparison ---- I wasn't sure how to do that but now I can have a go.

    I did change OR to AND before but I got nothing in my error email hhahaah so I changed it back. But i'll play with that now too and see what happens.


    Also i'm not expecting duplicates --- BUT if it did happen then it will either be a duplicate txn_id or user_email or very very very unlikely BOTH hahhhaa

    All i'm thinking to do is IF it did arise and there was duplicate(s) -- I want to catch it and send error to myself.


    So my meaniing is it's possible tp be ONE or THE OTHER or BOTH :-)

    anyway

    really appreciate yr help

    thank you

    LT
    back to the drawing board hahaha

  • #9
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi again MattF

    well here is my latest attempt
    no it doesn't work hahahhaha line 104
    syntax error, unexpected '}'


    PHP Code:
    while ($row mysql_fetch_assoc($result)){
    //echo $row["txn_id"];
    //echo $row["user_email"];
        
    if ($row["txn_id"] == $txn_id){
        
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n"
        
    }else{$content "Duplicate Txn ID:none "}; //LINE 104
        
    if ($row["user_email"] == $user_email){
        
    $content .= "Duplicate Email Addresses: " $row["user_email"] . "\n\n"
        
    }else{$content .= "Duplicate Email:none "};
        }
     
    mail($notify_email,"Duplicates Found",$content);

    LT

    Does the txn_id not auto-increment?
    No Sir.
    Last edited by low tech; 12-06-2010 at 03:02 PM.

  • #10
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi MattF

    ok my last effort --- late now

    this one finds the txn_id but not the user_email when both duplicates are sent

    so I guess it passes and has done enough once its found txn_id --- in other words --- crap code hahaahhaha


    PHP Code:
    while ($row mysql_fetch_assoc($result)){
    //echo $row["txn_id"];
    //echo $row["user_email"];
    if ($row["txn_id"] == $txn_id)
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n";
    if (
    $row["user_email"] == $user_email)
    $content .= "Duplicate Email Addresses: " $row["user_email"] . "\n\n";
    }
    mail($notify_email,"Duplicates Found",$content);

    LT

  • #11
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You're overwriting your $content var whenever you match the id.

    Code:
    $content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
    You need the .= rather than just =.

  • Users who have thanked MattF for this post:

    low tech (12-06-2010)

  • #12
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi MattF

    Thank you very much for yr help.


    Can I ask you --- post #9 -- I did this

    PHP Code:
      if ($row["txn_id"] == $txn_id){ 
        
    $content "Duplicate Txn ID: " $row["txn_id"] . "\n\n" 
        
    }else{$content "Duplicate Txn ID:none "}; 

    BUT the braces {} seemed to be wrong


    are they wrong/not needed within a WHILE loop?

    I mean I don't have them in my last attempt and the code worked.

    LT


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •