CallMeLeonardo
CallMeLeonardo

Reputation: 86

"mysqli_fetch_array() expects parameter 1" error, while working with fetch / array

I was looking for about an hour for a solution of my issue. I found several similar questions, but no one helped me. And I also realised, that a lot of people gets this error message. Because I'm really frustrated with my issue, i will ask you to help me.

I'm trying to select some stuff out of my database and store it inside an array. After that, I want to fill my table with the array and show it inside my modal.

But I got an error every time I tried to story my select inside an array.

The affected line (row 275) is the line, with this code: while($row= mysqli_fetch_array($user))

This is what my code looks like right now:

My Modal (geheim.php)

<div id="modal-timeline" class="modal modal-fixed-footer">
    <div class="modal-header">
      <h4>Timeline</h4>
    </div>
    <div class="modal-content">
      <?php
      include '../db.php';
      $statement = $pdo->prepare("SELECT * FROM timeline");
      $user = $statement->fetch();
      ?>
      <div>
        <td>Login Page Database</td>
     <table border="1">
        <th>Benutzer</th>
        <th>Tätigkeit</th>
        <th>Zeitstempel</th>
        </tr>

    <?php

         while($row=  mysqli_fetch_array($user))
         {
             ?>
        <tr>
            <td><?php echo $row['benutzer']; ?></td>
            <td><?php echo $row['taetigkeit']; ?></td>
            <td><?php echo $row['zeitstempel']; ?></td>
        </tr>

      </table>
        </div>
        <?php
        }
        ?>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Abbrechen</a>
      <button id="submit" class="btn waves-effect waves-light blue bestaetigen" type="button" name="bestaetigen">Bestätigen
    <i class="material-icons right">send</i>
  </button>
  </form>

    </div>
  </div>

The included connection (db.php)

<?php
    $pdo = new PDO('mysql:host=localhost;dbname=einteilungsplan', 'root', '');
?>

My Database (mysql)

Database

And of course, my error message looks like this:

Error Message

Error message

Thanks a lot for every help

Upvotes: 0

Views: 294

Answers (1)

DD77
DD77

Reputation: 816

Try below code may be it will work for you.

$statement = $pdo->prepare("SELECT * FROM timeline");
$statement->execute();
$result_data = $statement->fetchAll( PDO::FETCH_ASSOC );

...

foreach( $result_data as $row ) {
 ...  
}

Upvotes: 1

Related Questions