i cant seem to figure this out. the rating is coming out all screwed up.
i
made the code easier to read by just making a test version of the
original function. i added .= to the test part it seems to be
evaluating the middle three as average in the else statement even
though it evaluated the rating -5.
any help is much appreciated,
<style>
.items-box{ font-size:16px;}
.item{background-color: #CCCCCC; border-bottom:solid 2px; }
.greaterthan{ color: #006600;padding:0px 10px;}
.lessthan{ color: #FF0000;padding:0px 10px;}
.average{ color: #0066FF;padding:0px 10px;}
.rating{ font-size:14px; font-weight:bold; padding:0px 10px;}
</style>
<div class="items-box">
<?php
$tree = array( array( id => "1",
name => "1st",
rating => "5",
parentid => "0"
),
array( id => "2",
name => "reply",
rating => "0",
parentid => "1"
),
array( id => "3",
name => "reply",
rating => "-5",
parentid => "1"
),
array( id => "4",
name => "2nd topic",
rating => "-1",
parentid => "0"
),
array( id => "5",
name => "reply 2nd",
rating => "5",
parentid => "4"
),
array( id => "6",
name => "reply",
rating => "3",
parentid => "1"
)
);
function itemsFormat($parent, $tree) {
foreach ($tree as $item) {
if($parent == $item['parentid']) {
///rating
$rating = $item['rating'];
if($rating >= 5){
$test.='<span class="greaterthan">greater than or equal to 5</span>';
}elseif($rating <= -5){
$test.='<span class="lessthan">less than or equal to -5</span>';
}else{
$test.='<span class="average">average</span>';
}
$output .= '<div class="item">';
$output .= '<span>' . $item['name'] .'<span class="rating">rating:'.$item['rating'].'</span>_test:'.$test. '</span>';
$output .= '</div>';
$output .= itemsFormat($item['id'], $tree);
}
}
return $output;
}
echo itemsFormat(0, $tree);
echo '</div>';
///output raw array for testing
//print '<pre>'; var_dump($tree); print '</pre>';
die();
?>