替换字段中的表值

时间:2012-09-25 09:44:08

标签: php mysql database opencart

我有一个数据库名称q8marketz里面有一个表product。该表有许多字段,例如: - 产品ID,型号,数量,运输等......

我已将许多产品上传到我的表格...有一个字段shipping,所有产品的shipping值已设置为1,所以现在我要设置所有产品运送价值均为0

任何人都可以帮助我吗? 对不起,我的英语不完美...

下面给出了两个产品细节......


===Database q8marketz

== Table structure for table product

|------
|Field|Type|Null|Default
|------
|//**product_id**//|int(11)|No|
|model|varchar(64)|No|
|downpayment|varchar(32)|No|
|sku|varchar(64)|No|
|upc|varchar(12)|No|
|ean|varchar(14)|No|
|jan|varchar(13)|No|
|isbn|varchar(13)|No|
|mpn|varchar(64)|No|
|location|varchar(128)|No|
|quantity|int(4)|No|0
|stock_status_id|int(11)|No|
|image|varchar(255)|Yes|NULL
|manufacturer_id|int(11)|No|
|shipping|tinyint(1)|No|1
|price|decimal(15,4)|No|0.0000
|points|int(8)|No|0
|tax_class_id|int(11)|No|
|date_available|date|No|
|weight|decimal(15,8)|No|0.00000000
|weight_class_id|int(11)|No|0
|length|decimal(15,8)|No|0.00000000
|width|decimal(15,8)|No|0.00000000
|height|decimal(15,8)|No|0.00000000
|length_class_id|int(11)|No|0
|subtract|tinyint(1)|No|1
|minimum|int(11)|No|1
|sort_order|int(11)|No|0
|status|tinyint(1)|No|0
|date_added|datetime|No|0000-00-00 00:00:00
|date_modified|datetime|No|0000-00-00 00:00:00
|viewed|int(5)|No|0
== Dumping data for table product

|886|BA-HANDBAGS-001ss| | | | | | | |aaaa|95|7|data/hand-bags.jpg|7|1|32.5000|25|0|2012-09-03|0.00000000|1|0.00000000|0.00000000|0.00000000|1|1|1|1|1|2012-09-25 13:00:18|0000-00-00 00:00:00|0
|883|BA-HANDBAGS-001ss| | | | | | | |aaaa|95|7|data/hand-bags.jpg|7|1|32.5000|25|0|2012-09-03|0.00000000|1|0.00000000|0.00000000|0.00000000|1|1|1|1|1|2012-09-17 14:08:08|2012-09-25 13:00:06|9
== Table structure for table product

|------
|Field|Type|Null|Default
|------
|//**product_id**//|int(11)|No|
|model|varchar(64)|No|
|downpayment|varchar(32)|No|
|sku|varchar(64)|No|
|upc|varchar(12)|No|
|ean|varchar(14)|No|
|jan|varchar(13)|No|
|isbn|varchar(13)|No|
|mpn|varchar(64)|No|
|location|varchar(128)|No|
|quantity|int(4)|No|0
|stock_status_id|int(11)|No|
|image|varchar(255)|Yes|NULL
|manufacturer_id|int(11)|No|
|shipping|tinyint(1)|No|1
|price|decimal(15,4)|No|0.0000
|points|int(8)|No|0
|tax_class_id|int(11)|No|
|date_available|date|No|
|weight|decimal(15,8)|No|0.00000000
|weight_class_id|int(11)|No|0
|length|decimal(15,8)|No|0.00000000
|width|decimal(15,8)|No|0.00000000
|height|decimal(15,8)|No|0.00000000
|length_class_id|int(11)|No|0
|subtract|tinyint(1)|No|1
|minimum|int(11)|No|1
|sort_order|int(11)|No|0
|status|tinyint(1)|No|0
|date_added|datetime|No|0000-00-00 00:00:00
|date_modified|datetime|No|0000-00-00 00:00:00
|viewed|int(5)|No|0

2 个答案:

答案 0 :(得分:1)

您可以轻松使用这样的更新查询:

update product set shipping=0;

这会将所有行更新为0。

如果您只想指定某些选定的行,可以添加where子句来限制您更新的行数,如下所示:

update product set shipping=0 where points>2;

这会更新points值大于2的所有行。

编辑:代码可以直接从mysql控制台运行,也可以通过PHP中的数据库调用运行,如下所示:

$dbh = new PDO($hostname, $username, $password);
$sql='update product set shipping=0 where points>2';
$stmt = $dbh->query($sql);

答案 1 :(得分:0)

您可以使用SQL UPDATE语句更新表中的现有记录。

SQL UPDATE语法:

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

对于您的考试使用:

UPDATE product
SET shipping=0;

==>代码可以直接从mysql控制台运行。

要使用PHP Call,请尝试以下代码:

<?php
 $dataBase = new PDO($hostname, $username, $password);
 $sqlQuery ='update product set shipping=0';
 $stmt = $dataBase->query($sqlQuery );
?>