【发布时间】:2013-12-12 12:44:28
【问题描述】:
注意:
我是 php 和 mysql 的新手。
背景信息:
我有 +/- 30,000 种产品,它们来自 7 个不同的供应商,而且他们有很多相同的产品
假设我有 1 个产品,三个供应商有它,我需要发布价格最低的产品,而另外两个产品保持未发布状态
基本思路就是这个,这个要跑遍30000个产品,看看有没有匹配的,运行发布功能
SQL 设置:
有两个表xxxx_virtuemart_product和xxxx_virtuemart_product_prices
xxxx_virtuemart_product ▬▬▬ product_id,product_sku,published ▬▬▬一共有三行
xxxx_virtuemart_product_prices有两行▬▬▬product_id,product_price▬▬▬
我的一点点代码:
我有这个小代码,因为我卡住了,我如何检查是否有任何匹配项,然后运行查询以更改最低价格产品的发布值?
我知道有一种方法可以使用查询来检查匹配项,但不明白该怎么做
$query = "SELECT `product_sku` FROM `xxxx_virtuemart_product`";
$query_run = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_assoc($query_run)){
foreach ($row as $key => $ps){
}
}
下面的代码是检查价格(不是查询优化只是一个草稿)
$z = //products price;
$x = //products price;
$c = //products price;
if ($z >= $x && $c >= $x) {
//the this products published value to 1
}else if ($x >= $z && $c >= $z) {
//the this products published value to 1
}else if ($z >= $c && $x >= $c) {
//the this products published value to 1
}
谁能帮我解决这个问题?
感谢阅读
欢迎提出任何问题。
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial. -
谢谢你的提示会看看它
-
嗨 h2ooooooo,我知道 PDO 会有一个学习曲线,但从长远来看它看起来会更好,你的选择是什么?
-
我个人更喜欢 PDO。学习曲线并不像你想象的那么糟糕,你可以让一个类相当容易地为你处理常规查询。在我们工作的 DB 库中,我们只需使用
$db->FetchRows("SELECT foo FROM bar WHERE id = :id", array(":id" => 123))即可获得结果。