I have a list of urls stored in a database, and I want to run a bit of code that checks an array of urls vs what is stored in the database. If the value exists, I want that value from the array dropped.
So far, I have a database that contains 3 rows:
CREATE TABLE links
(
link_id INT(10) NOT NULL AUTO_INCREMENT,
url VARCHAR(255) NOT NULL,
last_visited TIMESTAMP,
PRIMARY KEY (link_id),
UNIQUE KEY (url)
)
And basically I'm just trying to insert the data vs a unique value via an INSERT command and if it fails, i'd like to remove that array value. Is this possible?
My bad code:
foreach ($urlArray as $url) {
$sql = "INSERT INTO linkz (url, last_visited) VALUES ('".$url."', NOW())";
if (!mysql_query($sql,$con)){
// remove array here somehow?
}
}
Is there a better way?
Any help would be appreciated, thanks! Tre