我浏览了建议的标题并找到了一些答案,但没有一个真正有效,所以我求助于你......
我有一个函数用于ob_start()
调用一个文件,其中的内容用作骨架。检索到内容后,我使用ob_end_clean()
.
我似乎只从第一次调用该函数时获得输出,之后仅此而已。我已经包含了一个代码转储,以防我做错了什么。
我还包含了从我的数据库调用 ( $dl->select ...
) 返回的内容的示例。我还确保数据确实是从我期望的数据库传回的。
Array
(
[0] => Array
(
[rev_id] => 7
[rev_temp_tree_id] => 2
[rev_tree_id] =>
[rev_status] =>
[rev_last_updated_by] => 0
[rev_authorized_by] =>
[rev_date_updated] => 1334600174
[rev_date_reviewed] =>
[rev_update_type] => 1
[temp_tree_id] => 2
[temp_tree_bag_size] => 250
[temp_tree_botanical_id] =>
[temp_tree_stem_size] => 0
[temp_tree_crown] => 0
[temp_tree_price] => 0
[temp_tree_height] => 0
[temp_tree_plant_date] => 0
[temp_tree_review_id] =>
[temp_tree_comments] =>
[temp_tree_marked_move] => 0
[temp_tree_initial_location] =>
[temp_tree_coord] =>
[temp_tree_name] => TEST
[temp_tree_sale_status] => 0
[temp_tree_open_ground] =>
[temp_tree_block] => 0
[temp_tree_row] => 0
)
)
和代码...
<?php
function print_trees($trees){
$return = '';
ob_start();
include_once('skeletons/tree.html');
$tree_skeleton= ob_get_contents();
ob_end_clean();
$search=array("[tree_id]", "[tree_name]", "[Classes]", "[rev_id]");
foreach($trees as $t){
$replace=array($t['temp_tree_id'], $t['temp_tree_name'].' ['.$t['temp_tree_id'].']', 'temp_tree', $t['rev_id']);
$return.=str_replace($search,$replace,$tree_skeleton);
}
return $return;
}
switch ($_GET['mode']){
case 'trees' :
$db_status = '';
$new_trees = $dl->select('tree_review AS tr LEFT JOIN temp_tree_trees AS tt ON tr.rev_temp_tree_id=tt.temp_tree_id', 'tr.rev_update_type="1"');
echo '<h2>New Trees</h2>';
if($dl->totalrows>0){
echo print_trees($new_trees);
}
else{
echo 'no new trees for review';
}
echo '<br /><br />';
$new_trees = $dl->select('tree_review AS tr LEFT JOIN temp_tree_trees AS tt ON tr.rev_tree_id=tt.temp_tree_id', 'tr.rev_update_type="2"');
echo '<h2>Updated Trees</h2>';
if($dl->totalrows>0){
echo print_trees($new_trees);
}
else{
echo 'no update trees for review';
}
echo '<br /><br />';
$new_trees = $dl->select('tree_review AS tr LEFT JOIN temp_tree_trees AS tt ON tr.rev_tree_id=tt.temp_tree_id', 'tr.rev_update_type="3"');
echo '<h2>Moved Trees</h2>';
if($dl->totalrows>0){
echo print_trees($new_trees);
}
else{
echo 'no moved trees for review';
}
echo '<br /><br />';
$new_trees = $dl->select('tree_review AS tr LEFT JOIN temp_tree_trees AS tt ON tr.rev_tree_id=tt.temp_tree_id', 'tr.rev_update_type="4"');
echo '<h2>Duplicated Trees</h2>';
if($dl->totalrows>0){
echo print_trees($new_trees);
}
else{
echo 'no duplicated trees for review';
}
break;
}
?>
任何帮助,将不胜感激。
提前致谢。