SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Duplicates removal after inserting

    Hi Guys,

    I have a CSV file that will insert mobile numbers in to a database and use the following to build the table

    Code:
    CREATE TABLE IF NOT EXISTS `".$tablename."` (
      `number` varchar(11) NOT NULL,
      `message` varchar(160) DEFAULT NULL,
      `sent` varchar(1) NOT NULL DEFAULT '0',
      `date` timestamp NULL DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    once the data has been inserted what command should i run to ensure that anything in the numbers in unique and remove any duplicates.

    I wish for this to be done once the data has been inserted so that if a user submit's a CSV with duplicate numbers they do not have to remove them or get an error.

  2. #2
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed via
    PHP Code:
    CREATE TABLE IF NOT EXISTS `".$tablename."` (
      `
    numbervarchar(11NOT NULL,
      `
    messagevarchar(160) DEFAULT NULL,
      `
    sentvarchar(1NOT NULL DEFAULT '0',
      `
    datetimestamp NULL DEFAULT NULL,
      
    PRIMARY KEY (`number`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1

    and doing the following to ignore duplicates in the numbers field.

    PHP Code:
    $db->prepare('
                INSERT IGNORE INTO `'
    .$tablename.'` (                                      
                    `number`
                ) VALUES ( 
                    ?           
                )
            '
    ); 


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
  •