Re: Need help with updating existing mysql records with something else
| From: | tamouse mailing lists | Date: | Sat, 12 Nov 2011 11:13:01 +0000 |
| Subject: | Re: Need help with updating existing mysql records with something else | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48094@lists.php.net to get a copy of this message | ||
2011/11/11 Amit Tandon <attand@gmail.com>:
> U can "update" the record with following
>
> ===========
> $result = mysql_query("UPDATE tax set mwool40_
> totqty = $res", $connection) or die("error
> updating database");
Won't this update every row in the table?
I think you'd want:
$result = mysql_query("UPDATE tax SET mwool40_totqty = $res
WHERE id=".$res['id'],$connection) or die("blah blah");
Where id is the identifier of the current record you're looking at
(however you've done that).
> if (mysql_affected_rows($connection) != 1 (/* no of rows that should be
> updated */)
> {
> die("Update problem") ;
> }
>
> The only issue is the where condition that you would put in the query
> UPDATE tax set mwool40_totqty = $res where ...
^This. Don't leave this out.
> ============
> regds
> amit
>
> "The difference between fiction and reality? Fiction has to make sense."
>
>
> 2011/11/11 Guru™ <nagendra802000@gmail.com>
>
>> Hi All,
>>
>> I want to update an existing mysql record with another value after
>> calculating it. Below is the code.
>>
>> <?php
>> $connection = mysql_connect("localhost", "root", "") or
>> die("Error
>> connecting to database");
>> mysql_select_db("maha", $connection);
>> $result = mysql_query("SELECT * FROM tax", $connection) or die("error
>> querying database");
>> $i = 0;
>> while($result_ar = mysql_fetch_assoc($result)){
>> ?>
>> <tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo
>> "class='body1'";}?>>
>> <td>
>> <?php
>> $res=$result_ar['mwool40_totqty']-10;
>> echo $res;
>> ?></td>
>> </tr>
>> <?php
>> $i+=1;
>> }
>> ?>
>>
>>
>> I want to append the $mwool40_totqty value with the calculated one "$res".
>> Let say initially the value of $mwool40_totqty is 50. and after calculation
>> its value became 40, then the code should edit/alter/update the value in
>> mysql table with integer 40. Please help me with this.
>>
>>
>> --
>> *Best,
>> *
>> *Guru™*
>>
>