gpt4 book ai didi

php - MySql 查询返回所有数据

转载 作者:行者123 更新时间:2023-11-29 18:07:22 25 4
gpt4 key购买 nike

我正在尝试使用复选框来查看我的数据库,但我不知道为什么,答案是由表的所有数据组成,而不是我想要的特定条目!

代码

$req_lieux = $sqlQuery->query("select lieux.nom from lieux, type_lieu WHERE lieux.id_type_lieu = type_lieu.ID");

PHP 代码:

<fieldset>
<legend class="title-color-bloc">Couleur</legend>
<?php
require_once 'search.php';
/* la requête est dans search.php */
while ($couleurs = $query_check_color->fetch())
{?>
<input class="color-choice" type="checkbox" id="color-choice<?php echo $couleurs['ID']; ?>" name="color-choice[]" value="<?php echo $couleurs['ID']; ?>">
<label for="color-choice<?php echo $couleurs['ID']; ?>"><?php echo $couleurs['couleur']; ?></label>
<?php
}
$query_check_color->closeCursor();
?>
</fieldset>
<fieldset>
<legend class="title-color-bloc">Lieux</legend>
<?php
/* la requête est dans search.php */
while ($types = $query_check_types->fetch())
{?>
<input class="type-choice" type="checkbox" id="type-choice<?php echo $types['ID']; ?>" name="type-choice[]" value="<?php echo $types['ID']; ?>">
<label for="type-choice<?php echo $types['ID']; ?>"><?php echo $types['libelle']; ?></label>
<?php
}
$query_check_types->closeCursor();
?>
</fieldset>
<input type="submit" value="Afficher" class="submit-btn" name="submit-btn">
</form>
<?php
if(isset($_POST))
{
if(!empty($_POST['type-choice']))
{
$type = implode("," , $_POST['type-choice']);
while ($type = $req_lieux->fetch())
{ ?>
<h1><?php echo $type['nom'] ?></h1>
<?php }
}
}
?>

感谢您的帮助!

最佳答案

您没有将查询结果限制为任何特定类型。

select lieux.nom from lieux, type_lieu WHERE lieux.id_type_lieu = type_lieu.ID

此查询将从lieux中选择type_lieu中存在记录的每条记录。

因此,如果您尝试使用特定的 type_lieu,那么您可以执行如下操作:

SELECT l.nom from lieux AS l INNER JOIN type_lieu AS tl ON l.id_type_lieu = tl.ID WHERE tl.type = xxxx

关于php - MySql 查询返回所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47717691/

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