four4swords Posted February 22, 2008 Share Posted February 22, 2008 hi, I have this problem here.. Where i want to update some info .. but only for ONE record.. Let's say i have a table like this.. Item | Type | Stock Apple | Food | 1 Orange | Food | 1 Cat |Animal | 1 Apple | Food | 1 Orange | Food | 1 Cat |Animal | 1 And I want just one row with the item CAT to decrease it's stock to zero.. mysql_query("UPDATE itemsSET Stock = '0' WHERE Type = 'Animal '") or die(mysql_error()); That bit of code there.. will change ALL my "ANIMAL" types to a stock of ZERO.. What can i do so that only ONE row is changed to ZERO? Thanks! Quote Link to comment Share on other sites More sharing options...
peranha Posted February 22, 2008 Share Posted February 22, 2008 You would have to insert an ID field, and have it referenced in the query instead of the type. Quote Link to comment Share on other sites More sharing options...
four4swords Posted February 22, 2008 Author Share Posted February 22, 2008 ouch.. lol I didn't add in an ID field! Is there any other way to do it?! Quote Link to comment Share on other sites More sharing options...
fenway Posted February 22, 2008 Share Posted February 22, 2008 ouch.. lol I didn't add in an ID field! Is there any other way to do it?! So add one. Quote Link to comment Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 ALTER TABLE <table name here> ADD COLUMN id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY BEFORE `Item` Quote Link to comment 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.