Home > OS >  php obstart() ,$output2= ob_get_clean();
php obstart() ,$output2= ob_get_clean();

Time:12-23

I have used ob_start() and $output2= ob_get_clean() in all my previous programs But all of sudden, for this current program I have faced "undefined variable $output2" when I run program. I would appreciate if some one have a look

code:

<ul>
<?php
require_once "classes/DBAccess.php";
// remoteserver I used db.php Elh wants to get database setting from *** for the first time, early bird
include "settings/db.php";
$db = new DBAccess($dsn, $username, $password);
$pdo = $db->connect();
$sql = "select categoryName, categoryId from category";
$stmt = $pdo->prepare($sql);
$rows = $db->executeSQL($stmt);
$rows = $pdo->query($sql);
foreach ($rows as $row):
$id = $row["categoryId"];
$name = $row["categoryName"];
?>
<li><a href="hype.php?id=<?= $id ?>"><?= $name ?></a></li>
<?php endforeach;
ob_start();
$output2= ob_get_clean();
include "templates/layout.html.php";
$pdo = null;
?>
</ul>

CodePudding user response:

Output buffering works by intercepting all output; anything in between ob_start() and ob_end_clear() is intercepted; any output that precedes ob_start() is not.

In this case, since the 2 statements follow each other, you're not intercepting anything at all.

  • Related