hoping to be schooled a little bit here in showing "no results". This is a working snippet, but I'd like to know if there is a more elegant way to show errors when comparing multiple values in an IF statement within a ForLoop... I could have 10 results with only 2 matching my if statement:
if($value["IsArchived"] == false && !preg_match("/^123 ABC/", $value["ProjectName"]))
Is there better way than capturing a count variable $totalToShow == 0 to show my "No Results" in a new IF statement or is that ok?
$obj = drupal_json_decode($result);
//used to show NO RECORDS or not... probably a more elegant way here?!
$totalToShow = 0;
//loop through the json data and add it to the $output array.
//NOTE: not checking if any are empty
$output .= '<ul class="list-group" style="margin-bottom:15px;">';
//check if the obj is empty, if so, no records to display...
if (!empty((array) $obj)) {
foreach($obj as $key=>$value){
if($value["IsArchived"] == false && !preg_match("/^123 ABC/", $value["ProjectName"])){
$totalToShow++;
//output project name link to project # and append start/end date after link.
$output .= '<li class="list-group-item"><strong>' . $value["ProjectName"] . '</strong> ('. _abc_date($value["CommentStart"]) . " - " . _abc_date($value["CommentEnd"]).') ';
if($lrnmore != ""){
$output .= ' | <a href="CommentInput?project='.$value["ProjectNumber"].'">'. $lrnmore .'</a>';
}
$output .= '| <a href="ReadingRoom?project='.$value["ProjectNumber"].'">View Comments</a><br/>';
$output .= '<ul><li>' . $value["Description"] . '</li></ul>';
$output .= "</li>";
}
}
if($totalToShow == 0){
$output .= '<li class="list-group-item">No Records to Display</li>';
}