PHP动态下拉菜单
我有 2 个下拉菜单,可以从数据库中检索文件。但当我尝试获取第二个文件时,它给了我一个错误。
第一个下拉列表已成功检索,但第二个下拉列表给我一个错误?
PHP 类中
class treatment{
function __construct($mysqli){}
// Get treatment list
function get_t_dermal_filler(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_dermal_filler ORDER BY t_dermal_name ASC");
while ($r = $q->fetch_array(MYSQLI_ASSOC)) :
echo '<option value="' . $r['id_t_dermal_filler'] . '" >' . $r['t_dermal_name'] . '</option>';
endwhile;
$mysqli->close();
}
// Get treatment list
function get_t_wrinkle_rel(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_wrinkle_rel");
while ($r = $q->fetch_array(MYSQLI_ASSOC)) :
echo '<option value="' . $r['id_t_wrinkle_rel'] . '" >' . $r['t_wrinkle_name'] . '</option>';
endwhile;
$mysqli->close();
}
}
在网页的
$treatment = new treatment($mysqli);
<?= $treatment->get_t_dermal_filler();?>
<?= $treatment->get_t_wrinkle_rel();?>
出现错误
<b>Warning</b>: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: Couldn't fetch mysqli in <b>
ive got 2 dropdown menu that retrieve the file from the database. but it gives me an error when im trying to get the the 2nd file.
The first dropdown, successfully retrieved but the second one gives me an error?
in PHP class
class treatment{
function __construct($mysqli){}
// Get treatment list
function get_t_dermal_filler(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_dermal_filler ORDER BY t_dermal_name ASC");
while ($r = $q->fetch_array(MYSQLI_ASSOC)) :
echo '<option value="' . $r['id_t_dermal_filler'] . '" >' . $r['t_dermal_name'] . '</option>';
endwhile;
$mysqli->close();
}
// Get treatment list
function get_t_wrinkle_rel(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_wrinkle_rel");
while ($r = $q->fetch_array(MYSQLI_ASSOC)) :
echo '<option value="' . $r['id_t_wrinkle_rel'] . '" >' . $r['t_wrinkle_name'] . '</option>';
endwhile;
$mysqli->close();
}
}
in webpage
$treatment = new treatment($mysqli);
<?= $treatment->get_t_dermal_filler();?>
<?= $treatment->get_t_wrinkle_rel();?>
the error
<b>Warning</b>: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: Couldn't fetch mysqli in <b>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是 mysqli 的关闭
将它们从两个函数中删除,然后在询问所有数据后,将其关闭。
I think the problem is the closing of the mysqli
remove them from both functions, and then after asking for all the data, close it.