• PHP Help
  • I don't know some clever title to do with php lazy loader

For some reason the code isn't incriminating and I'm getting the error

Notice: Undefined variable: id
<?php

error_reporting(E_ALL); // Error engine - always TRUE!
ini_set('display_errors', TRUE); // Error display - FALSE only in production environment or real server
ini_set('log_errors', TRUE); // Error logging engine
ini_set('error_log', 'errors.log'); // Logging file path

session_start(); 
    setlocale(LC_CTYPE, "en_US.UTF-8");
    require_once "classes/Database.php";
    $personsDB = new Database();
    $page = $_GET["page"] ?? 0;
    $thisScript = "get_records.php";
	$id = $_SESSION['id'] ?? '';
	$offset = 3;
    $articlesPerLoad = 2;
	try{
	$q = $personsDB->prepare("SELECT reviewId, shopId ,review FROM reviews WHERE shopId = :id ORDER BY reviewId limit $articlesPerLoad offset :offset");
	$q->bindValue(':id', $id, PDO::PARAM_INT);  
$q->bindValue(':offset', $offset, PDO::PARAM_INT);
articles($q,$page,20,$articlesPerLoad,$thisScript); }catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } function articles($q,$page,$howmany,$articlesPerLoad,$thisScript){ $nextPage=$page+$articlesPerLoad; $q->execute(); $rows = $q->fetchAll(\PDO::FETCH_ASSOC); foreach($rows as $i=>$row) { echo "<article>"; echo $row['review']; // echo "<img height=300 src='/people/images/{$row['reviewId']}{$row['review']}'>"; if ($articlesPerLoad==$i+1){ echo "<a class=more href='$thisScript?id={$id}&page={$nextPage}'>more</a>"; } echo "</article>"; } } ?>

    "Incriminating"?

    The function articles uses $id but never defines it; the complaint is about line 36 or thereabouts, yeah?

      Um I meant incrementing, for some reason it's saying it's a spelling error yet it's in the dictionary? Odd

      $id = $_SESSION['id'] ?? '';
      

      That's it defined, no?

        Globally, yes, but not inside the articles function.

          Ah I thought it wouldn't need to be in there too, thanks

            [upl-image-preview url=https://board.phpbuilder.com/assets/files/2019-04-15/1555339568-732575-image.png]

              Write a Reply...