[英]How can I set one column in a table where a column in another table has a certain value?
I have two tables, one contains a lot of product information such as product_name product_id etc and the other contains a list of product_ids and where or not that product is marked as on sale. 我有两个表,一个表包含很多产品信息,例如product_name product_id等,另一个表包含product_id的列表以及该产品在何处标记为正在销售。 I would like to be able to create something that I can run regularly through a Chron job which will look at table1.product_discount_id and if the product has anything in that column other than 0 it will update table2.product_on_sale to yes.
我希望能够创建可以通过Chron作业定期运行的内容,该作业将查看table1.product_discount_id,并且如果产品在该列中除0以外的任何内容,它将table2.product_on_sale更新为yes。 I am having trouble with understanding how to make sure that I only alter the fields for the products with a discount id of anything other than 0. I have got this far in the php script:
我在理解如何确保只更改折扣ID为0以外的其他商品的字段时遇到了麻烦。我在php脚本中已经做到了这一点:
mysql_connect("myhost", "mydb", "mypassword") or die(mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT * FROM jos_vm_product WHERE product_discount_id != '0'");
while($row = mysql_fetch_array($result))
{
echo $row['product_id'];
echo ",";
}
and that will produce a list of the product_ids for the products I wish to change the table2.product_on_sale field to yes. 这将生成我希望将table2.product_on_sale字段更改为yes的产品的product_id列表。 I'd like to then say if the product ids previously retrieved match a product_id in table2.product_on_sale field then change to yes.
然后,我想说一下先前检索的产品ID是否与table2.product_on_sale字段中的product_id匹配,然后更改为yes。 Any help would be greatly appreciated.
任何帮助将不胜感激。
Regards Ali. 问候阿里。
您不应该使用Cron作业进行更新,而应使用select中的联接来查找要出售的商品
mysql_query("update table1, table2 set table2.product_on_sale=true where table1.product_id=table2.product_id and table1.product_discount_id!=0")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.