-2

I'm getting this error:

Notice: Undefined variable: displaydata in C:\laragon\www\tasks\index.php on line 17

This is my index.php:

<?php
include('php/functions.php');
?>

<!doctype html>
<html ng-app>
  <head>
    <title>Opgaver</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  </body>
</html>

<?php

    while($row = $displaydata->fetch(PDO::FETCH_ASSOC)) {  
        if($row['created'] < date('Y-m-d')) {
            echo 'TEST';
        }
    }
    

?>

And this is my functions.php:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require('php/database.php');

class Functions {

    public function DisplayData() {
        try{
            $db = getDB();
            $displaydata = $db->prepare('SELECT * FROM tasks ORDER BY created ASC');
            $displaydata->execute();
            $data = $displaydata->fetch(PDO::FETCH_OBJ);
            return $data;
        }
        catch(PDOException $e) {
            echo '{"error":{"text":'. $e->getMessage() .'}}';
        }
    }

}

?>

I have already defined the public function, I don't see the problem.

Dharman
  • 30,962
  • 25
  • 85
  • 135
manny
  • 1

1 Answers1

0

Your function.php

public function DisplayData() {
        try{
            $db = getDB();
            $displaydata = $db->prepare('SELECT * FROM tasks ORDER BY created ASC');
            $displaydata->execute();                
            while($row = $displaydata->fetch(PDO::FETCH_ASSOC)) {  
              if($row['created'] < date('Y-m-d')) {
                 echo 'TEST';
                 }
               }    
    }
    catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
}

Your Html file:

<?php
include('php/functions.php');
?>

<!doctype html>
<html ng-app>
  <head>
    <title>Opgaver</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  </head>
  <body>
  </body>
</html>

<?php
$fun= new Functions();
$fun->DisplayData();

 ?>
Hammad Ahmed khan
  • 1,618
  • 7
  • 19