我不是程序員,我知道很少PHP,但我試圖修復一個店內自從一個代碼是給在PHP 5.4以下錯誤:轉換mysql_result到mysqli的
mysql_result( ):提供的參數不是一個有效的MySQL結果資源
這是代碼:
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
$id_produto = (INT)$products[$i]['id'];
$sql = tep_db_query("SELECT p.manufacturers_id,m.manufacturers_cep,m.manufacturers_name FROM products p
LEFT JOIN manufacturers m ON m.manufacturers_id = p.manufacturers_id
WHERE p.products_id = '$id_produto'")OR DIE(mysql_error());
$id_fabricante = mysql_result($sql,'0','manufacturers_id');
$cep_fabricante = mysql_result($sql,'0','manufacturers_cep');
$nome_fabricante = mysql_result($sql,'0','manufacturers_name');
$id_fabricantes[$id_fabricante]['peso'] += $products[$i]['quantity']*$products[$i]['weight'];
$id_fabricantes[$id_fabricante]['cep'] = $cep_fabricante;
$id_fabricantes[$id_fabricante]['nome'] = $nome_fabricante;
}
我試圖改變它,有沒有更多的錯誤,但它仍然不是加工。這是做到這一點的正確方法嗎?
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
$id_produto = (INT)$products[$i]['id'];
$sql = tep_db_query("SELECT p.manufacturers_id,m.manufacturers_cep,m.manufacturers_name FROM products p
LEFT JOIN manufacturers m ON m.manufacturers_id = p.manufacturers_id
WHERE p.products_id = '$id_produto'")OR DIE(mysql_error());
$row = mysqli_fetch_assoc($sql);
$id_fabricante = $row['manufacturers_id'];
$row = mysqli_fetch_assoc($sql);
$cep_fabricante = $row['manufacturers_cep'];
$row = mysqli_fetch_assoc($sql);
$nome_fabricante = $row['manufacturers_name'];
$id_fabricantes[$id_fabricante]['peso'] += $products[$i]['quantity']*$products[$i]['weight'];
$id_fabricantes[$id_fabricante]['cep'] = $cep_fabricante;
$id_fabricantes[$id_fabricante]['nome'] = $nome_fabricante;
}
你不能混合使用'mysql'函數和'mysqli',但以任何方式我們需要看到'tep_db_query'函數 –