ludwigvb Posted May 30, 2006 Share Posted May 30, 2006 Helloz,I'm trying to make a command to delete some mysql rows in a script.The code I use is:[code]$subcats = catDelete($cat_id); // gets the subcategories of the top category echo $subcats; // just a test to see that it outputs the right code echo '<br>'. $cat_id; // just a test to see the the $cat_id variable has not been changed $db = mysql_connect($server_name,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); mysql_query("DELETE FROM categories WHERE $subcats cat_id = $cat_id",$db) or die(mysql_error()); echo $lang_info_del; // echos that the categories and subcategories has been deleted[/code]echo commands are to make sure I get the right code for the mysql query that deletes the rows$subcats echos:cat_id=71 AND cat_id=72 ANDWhen I try to delete a category that has sub categories rows are not getting deletedWhen I try to delete a category with no subcategories the command is executed and the row gets deleted. Any tips?Thanks in advance!Spyros Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 This is a bit odd. How can a row have cat_id=71 AND cat_id=72 AND... ? Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/#findComment-40253 Share on other sites More sharing options...
ludwigvb Posted May 30, 2006 Author Share Posted May 30, 2006 [!--quoteo(post=378388:date=May 30 2006, 06:05 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 06:05 PM) [snapback]378388[/snapback][/div][div class=\'quotemain\'][!--quotec--]This is a bit odd. How can a row have cat_id=71 AND cat_id=72 AND... ?[/quote]The table "categories" I have is like this:cat_id | cat_name70 | name0171 | name0272 | name03If I executre the query:[code]DELETE FROM categories WHERE cat_id=71 AND cat_id=72 AND cat_id=70[/code]should it delete all the rows that have the specific cat_id s? Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/#findComment-40259 Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 No, it won't delete a thing, because that would mean:cat_id is 71, and is 72, and 70. This doesn't make any sense, it's one or another.If you want to delete all rows with any of these id's, use cat_id=x OR cat_id=y Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/#findComment-40261 Share on other sites More sharing options...
kenrbnsn Posted May 30, 2006 Share Posted May 30, 2006 No. You need to use the "OR" boolean.[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']DELETE[/span] [color=green]FROM[/color] [color=orange]categories[/color] [color=green]WHERE[/color] cat_id[color=orange]=[/color]71 [color=blue]OR[/color] cat_id[color=orange]=[/color]72 [color=blue]OR[/color] cat_id[color=orange]=[/color]70 [!--sql2--][/div][!--sql3--]Say each outloud and see which makes more sense.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/#findComment-40263 Share on other sites More sharing options...
ludwigvb Posted May 30, 2006 Author Share Posted May 30, 2006 I tried this just before your post... it worked (ofcourse)I spent 2 hours tryign to figure out what was wrong.Another question is:Am I stupid?BUT I have to answear this by my own !!! [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Thanks for your help [b]poirot[/b] Quote Link to comment https://forums.phpfreaks.com/topic/10777-delete-with-variable/#findComment-40268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.