简体   繁体   中英

php obstart() ,$output2= ob_get_clean();

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM