i have a problem.
i have a function that generates some random codes and stores them into an array,after this is inserts them into the database.
i need a function that compares the data from the array with the database and see if there are any matches dont insert,so there wont be any duplicates in the db.
i have made this so far :
PHP Code:
function verifyCodes( $sClientID = "" , $sCampaignID = "", $sCode ) { $arrConds = array(); if( $sClientID != "" ) { $arrConds[] = "`client_id` = ".(int)$sClientID.""; } if( $sCampaignID != "" ) { $arrConds[] = "`campaign_id` = ".(int)$sCampaignID.""; } $sQuery = "SELECT `code` FROM `codes`"; if ( count( $arrConds ) > 0 ) { $sQuery .= " WHERE ".implode( " AND ", $arrConds ); } $sQuery .= " AND "; $arrCodeConds = array(); foreach ($sCode as $key => $value) { $arrCodeConds[] = "code = '" .$value['code'] ."'"; } $sQuery .= implode(" OR " , $arrCodeConds); $this->oDB->query( $sQuery );
}
i need this function to return an array with the codes that arent in the database.
thank you .
|