gpt4 book ai didi

php - 不同mysql连接问题

转载 作者:行者123 更新时间:2023-11-29 08:17:17 24 4
gpt4 key购买 nike

我的 foreach 出现一些错误。错误如下:

bool(false) 警告:为/storage/content/34/123134 中的 foreach() 提供的参数无效

我有 bool(false) 因为我 var_dump 变量。我的代码如下所示:

$getTheOffers = mysql_query("SELECT * FROM `items_offer` , $connen");
foreach ($getTheOffers as $getTheOffer ) { ?>

$connen 是 mysql_connection 变量。我选择的数据库如下所示:

mysql_select_db($databaseInfo['sqldatabase'],$connen);

这里出了什么问题?感谢您的支持!

这里是完整的 foreach 和 mysql

    $getTheOffers = mysql_query("SELECT * FROM items_offer", $connen);
if( is_array($getTheOffers) )
{
foreach ($getTheOffers as $getTheOffer ) { ?>
<tr>
<td>
<?php if ($getTheOffer['offer_name'] == "plank") { ?>
<img src="images/plank.png" alt="Smiley face" height="42" width="42"> (Plank)
<?php } elseif ($getTheOffer['offer_name'] == "panel") { ?>
<img src="images/doubleplank.png" alt="Smiley face" height="42" width="42"> (Panel)
<?php } elseif ($getTheOffer['offer_name'] == "tape") { ?>
<img src="images/tape.png" alt="Smiley face" height="42" width="42"> (Tape)
<?php } elseif ($getTheOffer['offer_name'] == "bolt") { ?>
<img src="images/bolt.png" alt="Smiley face" height="42" width="42"> (Bolt)
<?php } elseif ($getTheOffer['offer_name'] == "nail") { ?>
<img src="images/nail.png" alt="Smiley face" height="42" width="42"> (Nail)
<?php } elseif ($getTheOffer['offer_name'] == "screw") { ?>
<img src="images/screw.png" alt="Smiley face" height="42" width="42"> (Screw)
<?php } ?>
</td>
<td><?php echo $getTheOffer['offer_amount'];?></td>
<td><?php echo $getTheOffer['offer_need'];?></td>
</tr>
<?php } } else echo "Not work!"; ?>

最佳答案

除了我在评论中指出的缺失代码之外,您的 mysql_query 调用似乎不正确。

试试这个:

$getTheOffers = mysql_query("SELECT * FROM items_offer", $connen);

另请尝试以下操作来查看您的查询发生了什么:

$result = mysql_query("SELECT * FROM items_offer", $connen);
$getTheOffers = mysql_fetch_array($result)
if( is_array($getTheOffers) )
{
foreach ($getTheOffers as $getTheOffer ) {
//... rest of your code goes here
}
} else{
// output error information
}

请引用mysql_querymysql_fetch_array在官方文档网站上了解更多信息。

关于php - 不同mysql连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342695/

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