0

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

4
  • @Chris Already checked the "possible dublicate before". Correct my if I'm wrong. But the issue with the "possible dublicate" is, that his query was false. I dont think that I have the same issue... Commented Jul 3, 2017 at 11:19
  • 1
    You mixing the PDO and mysqli. Please once refer the difference between both of them. Commented Jul 3, 2017 at 11:20
  • @DD77 Thanks a lot. I didn't knew the difference between PDO and mysqli... I always thought it's same and you can use it together. I'm trying to fix it with the new knowledge right now ;) Commented Jul 3, 2017 at 11:25
  • @CallMeLeonardo You are right, your issue was no exactly the same. However, the underlying problem remains the same: a bad request or a query not yet executed returns False. For that reason, I will maintain the dup link for other readers. In any case, happy to see that you finally solved your issue. Commented Jul 3, 2017 at 14:38

1 Answer 1

1

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 ) {
 ...  
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot :) Your code worked nearly perfect. Just a small error. It's foreach instead of for.
oops sorry! it was typo mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.