开发者

PHP dynamic dropdown

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 开发者_如何学JAVAASC");
    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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜