注意:
我是 php 和 mysql 新手。
背景信息:
我有 +/- 30,000 种产品,它们来自 7 个不同的供应商,而且他们有很多相同的产品
假设我有 1 个产品,三个供应商都有该产品,我需要发布价格最低的产品,而其他两个产品保持未发布状态
这是基本思想,必须运行 30,000 个产品并检查是否有任何匹配项并运行发布功能
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
}
有人可以帮我解决这个问题吗?
感谢您的阅读
有任何问题欢迎提问。
最佳答案
你的问题不是比较数组而是更多的算法。 我会尝试这种方式。 1)检索所有产品的SQL查询:sql_products 2)构建一个 HashMap ,其中键是产品SKU(参见:PHP Array)
构造 PHP hashmap:使用数组的数组。 例子 : 产品 map [] = 数组();
foreach sql_product 的 sql_products : - Product_map[sql_product[SKU]][] = array(sql_product[供应商], sql_product[价格], sql_product[信息]) 循环结束
然后再次循环构建的产品 map ,并按价格对每个产品记录进行排序:这意味着您必须编写一个函数来对数组(供应商、价格、信息)进行排序。
现在您有了产品 map :SKU => array(of array (supplier,price,information))
关于php - 比较一个数组中的数组值 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20543961/