supermerc Posted May 16, 2009 Share Posted May 16, 2009 Hey, I have a script that goes to a page, which is a vault filled with items and then it gets the image link and id from each item in it and adds it to my database. However I want my script to delete items from my database if they were taken away from the vault. Ive tried a few things but I dont know how to make it work. This is my code that adds to database: <?php foreach($images as $array) { foreach($array as $image) { $pattern2 = '#src=[\'"][^\'"]+/(.+?\.(?:png|jpe?g|gif))[\'"].+?ONMOUSEOVER=[\'"]itempopup\(event,\'(\d+)\'\)[\'"]#i'; preg_match_all($pattern2, $image, $match); $st = "SELECT * FROM items WHERE spath = '{$match[1][0]}'"; $qr = mysql_query($st); $check = mysql_fetch_array($qr); if ($check > 0){ if ($match[2][0] > 0){ $sa = "SELECT * FROM vault WHERE itemid = '{$match[2][0]}'"; $qv = mysql_query($sa); $check2 = mysql_fetch_array($qv); if ($match[2][0] !== $check2['itemid']){ $query = mysql_query("INSERT INTO vault (name, spath, itemid) VALUES ('{$check['name']}','{$check['spath']}','{$match[2][0]}')") or die(mysql_error()); } } } } } ?> thanks Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/ Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 A SQL like DELETE FROM vault WHERE itemid = {$match[2][0]}; ? Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/#findComment-835546 Share on other sites More sharing options...
supermerc Posted May 16, 2009 Author Share Posted May 16, 2009 Yes... but that will delete everything no? I need it to check everything in vault table and if there is something in the vault table that wasnt found in the vault page that im getting this from, it deletes that row from database Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/#findComment-835547 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 DELETE FROM vault WHERE itemid NOT IN ($list_itemid); ? $list_itemid is the itemids for the ones on the page. Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/#findComment-835559 Share on other sites More sharing options...
supermerc Posted May 17, 2009 Author Share Posted May 17, 2009 and how do i set that variable? Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/#findComment-835560 Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 if there is something in the vault table that wasnt found in the vault page that im getting this from From the vault page? I just went off what you said above. Link to comment https://forums.phpfreaks.com/topic/158433-help-with-delete/#findComment-835565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.