I have a webpage which is grabbing information from the string $details and looking for 'displayname' through search and displaying the results. This is LDAP Active Directory querying.
I need "$search .= "NameTitlePhoneMobileEmailDept\n";" to only show once a search has been completed. In it's current state, it repeats this line for every result. How can i make this line only show the once, up the top?
// Address Book Search
$search .= "<div class='border'>\n";
$search .= '<form class="search-form-wrapper" method="GET">
<input type="text" name="q" id="search" placeholder="Search for Staff..." required>
<input type="submit" value="go" id="submit">
</form><br><br>';
if (count($staff)) {
if (isset($_GET['q'])) {
$query = rawurlencode( strip_tags($_GET['q']));
$query = ucfirst($query);
foreach ($staff as $key => $details) {
if(substr_count($details['displayname'], $query)){
$search .= "<table class='address_book'><tr><th>Name</th><th>Title</th><th>Phone</th><th>Mobile</th><th>Email</th><th>Dept</th></tr>\n";
$search .= "<tr><td>{$details['displayname']}</td>\n";
$search .= "<td>{$details['title']}</td>\n";
$search .= "<td>{$details['telephonenumber']}</td>\n";
$search .= "<td>{$details['mobile']}</td>\n";
$search .= "<td><a href='mailto:{$details['mail']}'>{$details['mail']}</a></td>\n";
$search .= "<td>{$details['department']}</td>\n";
$search .= "</tr>\n";
$search .= "</table>\n";
}
}
}
}
$search .= "</div><br>";
$layout->content($search);
<table ...line to before the loop, and the</table>after the loop.$show = 0;. If it is0you echo the line and increase to1. If not0you don't echo.<table...row was above the foreach loop it would still only fire whenif (isset($_GET['q']))and instead only fire once. Also move the</table>below the closing bracket for the same reason.