+----+-----------+-----+| ID | name |price|+----+-----------+-----+| 1 |dest_tahiti| 10 || 2 |dest_bora | 20 || ...| ... | ... | +----+-----------+-----+ $price="SELECT price FROM rates WHERE name IN('dest_tahiti','dest_bora', ...) ";$price_prep= mysqli_query($connect,$price);$price_result= mysqli_fetch_array($price_prep);echo $prix_result["price"] //Just display price for dest_tahiti with WHERE = 'dest_tahiti';echo $prix_result["price"] //Just display price for dest_bora with WHERE = 'dest_bora';我想自定义的 值 WHERE name = ...进行相同的查询 与mysqli_fetch_array?你可以帮助我 ?
1 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
您可以在查询中包含名称作为输出。然后迭代返回的行并构建一个数组,其中索引是名称,值是价格。
$price = "SELECT name, price FROM rates WHERE name IN('dest_tahiti','dest_bora', ...) ";
$price_result = mysqli_query($connect, $price);
$prix_result = [];
while($row = mysqli_fetch_array($price_result, MYSQLI_ASSOC)) {
$prix_result[ $row['name'] ] = $row['price'];
}
echo $prix_result['dest_tahiti'];
echo $prix_result['dest_bora'];
- 1 回答
- 0 关注
- 176 浏览
添加回答
举报
0/150
提交
取消