Error to popular SELECT - Warning: mysql_fetch_array () expects parameter 1 to be resource

0

I'm not able to select my popular.

Below is my code:

 <select>
            <option>Selecione</option>

            <?php while($serv = mysql_fetch_array(getAllServicos())) { ?>
            <option value="<?php echo $serv['Codigo'] ?>"><?php echo $serv['Descricao'] ?></option>
            <?php } ?>

 </select>

getAllServices () function:

function getAllServicos(){
$database = open_database(); 

$sql = "SELECT Codigo, Descricao FROM 'tblservico' WHERE 'Status' = true";
$result = $database->query($sql);

if ($result->num_rows > 0) {
    $found = $result->fetch_all(MYSQLI_ASSOC);
}
close_database($database);
return ($found);    
}

Error:

  Warning: mysql_fetch_array () expects parameter 1 to be resource, array given in

    
asked by anonymous 16.08.2017 / 20:11

1 answer

1

getAllServicos() returns an array with the results of the database, it does not make sense to pass it to the bean function mysql_fetch_array() . You can pass right into a foreach:

<?php foreach(getAllServicos() as $serv) { ?>
    <option value="<?php echo $serv['Codigo'] ?>"><?php echo $serv['Descricao'] ?></option>
<?php } ?>

No printf() style;)

<?php
    foreach(getAllServicos() as $serv) {
        printf('<option value="%s"> %s </option>', $serv['Codigo'], $serv['Descricao']);
    }
?>
    
16.08.2017 / 20:15