www.webdeveloper.com
Results 1 to 2 of 2

Thread: Array compare

  1. #1
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    153

    Array compare

    Hello all,

    I want to compare for now, two sets of arrays. I pull data from sql tables and then compare the two. I am using the
    PHP Code:
    array_diff(); 
    function to compare the two arrays, but its showing it as a empty array. Is that because I am not telling it which demensions to look at? Like
    PHP Code:
    array_diff($array1[5], $array2[5]); 
    ?

    Here is the current code:
    PHP Code:
    <?php
    //Opens a connection to the Warta Database
        
    try {
            
    $wrd1 =  new PDO('mysql:host=localhost; dbname=*****''******''*****');
                
    $wrd1->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
                    
    $cale $wrd1->prepare(
                    
    "SELECT
                    start,
                    end,
                    repeat_freq,
                    repeat_int,
                    repeat_end,
                    allDay,
                    category_id,
                    description,
                    link,
                    venue,
                    address,
                    city,
                    state,
                    zip,
                    country,
                    contact,
                    contact_info,
                    access,
                    rsvp
                    FROM
                    wp_aec_event
                    "
    );
                        
    //executes SQL statement
                        
    $cale->execute();
                            
    //Set into array
                            
    $result $cale->fetchAll(PDO::FETCH_ASSOC);
                            
    print_r($result);
                            echo(
    "\n");
        

        
                
    //Opens a connection to the 1-sza Database
                
    try {
                    
    $wrd2 = new PDO('mysql:host=localhost; dbname=*****''*******''**');
                        
    $wrd2->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
                            
    $cale1 $wrd2->prepare(
                            
    "SELECT
                            start,
                            end,
                            repeat_freq,
                            repeat_int,
                            repeat_end,
                            allDay,
                            category_id,
                            description,
                            link,
                            venue,
                            address,
                            city,
                            state,
                            zip,
                            country,
                            contact,
                            contact_info,
                            access,
                            rsvp
                            FROM
                            wp_aec_event
                            "
    );
                                
    //executes SQL statement
                                
    $cale1->execute();
                                    
    //set into array
                                    
    $result1=$cale1->fetchALL(PDO::FETCH_ASSOC);
                                    
    print_r($result1);
                                    echo(
    "\n");
                                    
                                    
    //testing out php array compare
                                    
    $compare array_diff($result$result1);
                                    
    print_r($compare);
                }
                catch (
    PDOException $ex) {
                
    $msg $ex->errorInfo;
                
    error_log(var_export($msgtrue));
                die(
    "<p>Sorry, there was a unrecoverable database error.  Debug data has been logged.</p>");
                }

        }            
        catch (
    PDOException $ex) {
        
    $msg $ex->errorInfo;
        
    error_log(var_export($msgtrue));
        die(
    "<p>Sorry, there was a unrecoverable database error.  Debug data has been logged.</p>");
        };
    ?>
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    I suspect you will need to use array_udiff() so that you can access those second dimensions.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles