doddsey_65 Posted January 28, 2011 Share Posted January 28, 2011 what im trying to do is echo all of the results from the database query but add bold to results with a pid of 0. here is my code: $list = ''; $query = $link->query("SELECT * FROM ".TBL_PREFIX."forums ORDER BY f_lid ASC"); $result = $query->fetchAll(); foreach($result as $key => $val) { if($result[$key]['f_pid'] == 0) { $list .= '<b>'.$result[$key]['f_name'].'</b><br />'; } $list .= $result[$key]['f_name'].'<br />'; } echo $list; this works fine but the ones with a pid of 0 are displayed twice. once as bold and then once normal like so: General General New Features Testing Testing Sandbox Bugs my question is how to prevent this. Quote Link to comment https://forums.phpfreaks.com/topic/225938-foreach-loop/ Share on other sites More sharing options...
QuickOldCar Posted January 28, 2011 Share Posted January 28, 2011 $list = ''; $query = $link->query("SELECT * FROM ".TBL_PREFIX."forums ORDER BY f_lid ASC"); $result = $query->fetchAll(); foreach($result as $key => $val) { if($result[$key]['f_pid'] == 0) { $list .= '<b>'.$result[$key]['f_name'].'</b><br />'; } else { $list .= $result[$key]['f_name'].'<br />'; } } echo $list; Quote Link to comment https://forums.phpfreaks.com/topic/225938-foreach-loop/#findComment-1166445 Share on other sites More sharing options...
doddsey_65 Posted January 28, 2011 Author Share Posted January 28, 2011 so simple i should have thought about it(just finished night shift so theres my excuse). Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225938-foreach-loop/#findComment-1166446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.