gpt4 book ai didi

php - 在php sql语句中动态更改偏移量

转载 作者:行者123 更新时间:2023-11-30 00:13:35 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

(31 个回答)


7年前关闭。




我有以下查询,我想运行整个表,以便一个接一个地给我表的每个值。我需要在另一个查询中使用特定的行值。

for ($qoffset=0; $qoffset<=5; $qoffset++) {
$result = mysqli_query($con,"select nf865_virtuemart_products.product_sku from nf865_virtuemart_products order by product_sku asc limit 1 offset '".$qoffset."';");
echo "offset='$qoffset' <br>";
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo $row[0];
echo "<br>";
}

我得到的是“警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,给定的 bool 值”

结果似乎我得到了一个 bool 值(假),如果放置一个数字而不是一个变量,则查询工作正常。

请问有什么帮助吗?

进一步的sql:
mysqli_query($con,"Insert  Ignore Into nf865_virtuemart_product_medias(virtuemart_product_id,virtuemart_media_id,ordering) VALUES (
(Select nf865_virtuemart_products.virtuemart_product_id from nf865_virtuemart_products where nf865_virtuemart_products.product_sku LIKE '0100100'),
(Select nf865_virtuemart_medias.virtuemart_media_id from nf865_virtuemart_medias
where nf865_virtuemart_medias.file_url LIKE '%0100100 b.jpg' or nf865_virtuemart_medias.file_url LIKE %0100100 B.jpg'),2)");

我试过但还没有奏效:
$query1 = mysqli_query($con,"Select nf865_virtuemart_products.virtuemart_product_id from nf865_virtuemart_products where nf865_virtuemart_products.product_sku LIKE '".$product_id."'");

它需要以某种方式像这个'$variable',因为它没有返回任何东西,正如我所看到的。

最佳答案

删除偏移量周围的单引号。

$result = mysqli_query($con,"select nf865_virtuemart_products.product_sku  from nf865_virtuemart_products order by product_sku asc limit 1 offset ".$qoffset);

您还应该检查错误:
if ($result == false){
// you should have some logging method to log this error so you can check on it and return false to the calling function. I am using `die` here so you can at least see the error
die("Sql Error: " . mysqli_error($con));
}

关于php - 在php sql语句中动态更改偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23848392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com