Re: Adjust two or more mysql rows ?
| From: | John Holmes | Date: | Wed, 11 Aug 2004 18:14:55 +0000 |
| Subject: | Re: Adjust two or more mysql rows ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193490@lists.php.net to get a copy of this message | ||
Dave Carrera wrote:
I have a qty posted via a form field, lets say 46. In my mysql table I have two rows which I want to reduce their qty fields. 1 row has a qty of say 13 and the second has a qty of 50, making 63 in total. So I would like to say something like if $_POST[qty] is greater than row 1's qty then update row[qty] = 0, then minus what was the row qty, 13 , from $_POST[qty] to new var say $newqty = $_POST[qty]-$row[qty], this leaves 37. Then from the 2nd row take 37 from its qty of 50 leaving 13. End result being row 1's qty field = 0 and row 2's qty field = 13.I think you have a seriously flawed database structure. There is no "row 1" in a database, you know that, right? Pretty sure you can do what you're after, though, you'll just have to involve about four different queries and some PHP magic in the middle... -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com