在php页面中选择echo选项?
我正在尝试使用mysql结果回显select选项 我下面的代码只得到一个结果,但我在mysql数据库中有5个结果 PHP代码:在php页面中选择echo选项?,php,mysql,Php,Mysql,我正在尝试使用mysql结果回显select选项 我下面的代码只得到一个结果,但我在mysql数据库中有5个结果 PHP代码: if( ! $stmt = $db_conx->prepare("SELECT id, product_name FROM $storeShop ORDER by id") ) { die( $db_conx->error ); } $dropdownlist_list = ""; $stmt->bind_param('i', $id); if (
if( ! $stmt = $db_conx->prepare("SELECT id, product_name FROM $storeShop ORDER by id") ) {
die( $db_conx->error );
}
$dropdownlist_list = "";
$stmt->bind_param('i', $id);
if ( ! $stmt->execute() ) {
die( $stmt->error );
}
$stmt->bind_result($id, $product_name);
$stmt->store_result();
while($stmt->fetch()) {
$valuesss[] = array('id'=>$id, 'product_name'=>$product_name);
$dropdownlist_list = '<option data-filter="'.$product_name.'">'.$product_name.'</option>';
}
/* close statement */
mysqli_stmt_close($stmt);
HTML代码:
<select id="galleryfilter" class="form-control pull-left">
<?php echo $dropdownlist_list; ?>
</select>
有人能告诉我怎么了吗
谢谢您必须附加新选项,目前您正在从数据库中分配最后一个值 这将有助于:
$dropdownlist\u list.=.$product\u name 您必须附加新选项,当前您正在从数据库分配最后一个值 这将有助于: $dropdownlist\u list.=.$product\u name 你每次都在过度使用你的选项字符串。你需要考虑其他的选择 你每次都在过度使用你的选项字符串。您需要添加其他选项您必须使用$dropdown\U list.=而不是=这将附加新选项 这导致:
$dropdown_list = "";
while($stmt->fetch()) {
$valuesss[] = array('id'=>$id, 'product_name'=>$product_name);
$dropdown_list .= '<option data-filter="'.$product_name.'">'.$product_name.'</option>';
}
您必须使用$dropdown_list.=而不是=这将附加新选项
这导致:
$dropdown_list = "";
while($stmt->fetch()) {
$valuesss[] = array('id'=>$id, 'product_name'=>$product_name);
$dropdown_list .= '<option data-filter="'.$product_name.'">'.$product_name.'</option>';
}
每次加载新语句时,当前解决方案将覆盖现有字符串 试试这个:
$dropdownlist_list = "";
while($stmt->fetch()) {
$valuesss[] = array('id'=>$id, 'product_name'=>$product_name);
$dropdownlist_list .= '<option data-filter="'.$product_name.'">'.$product_name.'</option>';
}
HTML:
每次加载新语句时,当前解决方案将覆盖现有字符串 试试这个:
$dropdownlist_list = "";
while($stmt->fetch()) {
$valuesss[] = array('id'=>$id, 'product_name'=>$product_name);
$dropdownlist_list .= '<option data-filter="'.$product_name.'">'.$product_name.'</option>';
}
HTML:
你必须使用$dropdown_list.=而不是=@RaphaelMüller,谢谢你,伙计。愚蠢的错误..你必须使用$dropdown_list.=而不是=@RaphaelMüller,谢谢你,伙计。愚蠢的错误。。
<select id="galleryfilter" class="form-control pull-left">
<?php
foreach ($values as $value) echo '<option data-filter="'.$value['product_name'].'">'.$value['product_name'].'</option>';
?>
</select>