Skip to content
Advertisement

MySQL returns wierd result with normal query

So I have this code:

    <?php
    $main = new Main;
    $conn = $main->db_connect();
    $module = $conn->prepare("SELECT * FROM modules");
    $modulelist = $module->execute();
    $modulelist = mysqli_fetch_array($module->get_result());
    var_dump($modulelist);

And it returns this instead of the normal values in the table:

array(12) {

[0]=> int(2) [“ID”]=> int(2) 1=> string(7) “anderes” [“Naam”]=> string(7) “anderes” [2]=> string(4) “0.00” [“Beschrijving”]=> string(4) “0.00” [3]=>
string(4) “0.00” [“Prijs”]=> string(4) “0.00” [4]=>
string(0) “” [“Prijsweergave”]=> string(0) “” [5]=>
int(2) [“Termijn”]=> int(2) }

This is the table:Table

Advertisement

Answer

I assume your issue is that the way you have written your code, you only ever get One result printed from a multiple result query.

The $module->get_result() can only be called once as it gets the whole resultset the first time, so the second call will return nothing.

$module = $conn->prepare("SELECT * FROM modules");
$modulelist = $module->execute();
$results = $module->get_result();
while ( $row = $results->fetch_assoc() ){
    var_dump($row);
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement