SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2002
    Location
    Louisville, KY
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple question on comparing data

    i have a list of transaction id's in an array in PHP. i want to see if these transaction id's are in a mysql table field. if they aren't, i want to create new rows in this table with the new trans_id's.

    anyone have any idea how i can do this? i'm stumped.

  2. #2
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this might work:

    PHP Code:
    $ids = array(1,2,3,4,5);
    $idhash "SELECT " implode(" AS id UNION ALL SELECT "$ids);

    $sql "INSERT INTO transactions(trans_id, amount)
            SELECT n.id, 99
            FROM (
    {$idhash}) AS n
                LEFT JOIN transactions AS t ON n.id = t.trans_id
            WHERE t.trans_id IS NULL"



Bookmarks

Posting Permissions

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