1

I have two files : - The first is where my sql query are defined - The second where I call the function

Here is my code from the first file :

function select_categories($pdo){
        $sql = 'SELECT * FROM categories ;';
        $query = $pdo->prepare($sql);
        $query->execute();
        $tableau = $query->fetchALL(PDO::FETCH_ASSOC);
        return $tableau;
    }

And here is the code from my second file :

<?php
    include('includes/sql.php');

    function liste_categories(){
        echo select_categories($tableau);
    }

?>

I have to display my categories in a HTML list but for the moment I get an error "Undefined variable: tableau in /iut/users/vogel/public_html/info2/Galerie/includes/affichage.php on line 5"

Théo Vogel
  • 105
  • 1
  • 10
  • 2
    Where is `$tableau = '';` located? The basic issue it that `$tableau` is not within the scope of `liste_categories()`. – MonkeyZeus May 08 '19 at 16:15
  • If you use `require` or `require_once`, it will probably throw an error. Look here: [Difference between require, include, require\_once and include\_once?](https://stackoverflow.com/questions/2418473/difference-between-require-include-require-once-and-include-once). Then look [here](http://www.geeksengine.com/article/php-include-path.html). – paulsm4 May 08 '19 at 16:16
  • @paulsm4 Definitely not a dupe of that... – MonkeyZeus May 08 '19 at 16:17
  • Thank you a lot ! – Théo Vogel May 08 '19 at 16:35

0 Answers0