Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'connect.php';
- if(isset($_POST['search_term']) == true && empty($_POST['search_term'])==false){
- $search_term = mysql_real_escape_string(trim($_POST['search_term']));
- $terms = explode(" ", $search_term);
- foreach ($terms as $term) {
- $query = mysql_query("SELECT * FROM `clients` WHERE `last_name` LIKE '$term%' OR `first_name` LIKE '$term%' OR `company` LIKE '$term%' LIMIT 3");
- $query2 = mysql_query("SELECT * FROM `users` WHERE `last_name` LIKE '$term%' OR `first_name` LIKE '$term%' LIMIT 3");
- $emps = array(); // TO HOLD THE EMPLOYEES WHO MATCH
- $clients = array(); // TO HOLD THE CLIENTS WHO MATCH
- $clientStorage = array();
- while(($row = mysql_fetch_assoc($query)) != false){
- //if the client id is not in the array clientStorage then
- //the client is unique, now we must
- // add this clients id to to clientStorage
- if(!(in_array($row[0], $clientStorage))){
- array_push($clientStorage, $row[0]);
- // PRINT OUT THE SEARCH RESULT
- echo "<li><span class='searchName'>" . $row['first_name'] . " " . $row['last_name'] . "</span><span class='label pull-right'>Client</span>";
- if(!empty($row['company'])){
- echo "<br><p class='noMargin'><small><em>" . $row['company'] . "</em></small></p>";
- }
- echo "</li>";
- echo "<span class='hidden' id='searchId'>" . $row['id'] . "</span>";
- echo "<span class='hidden' id='type'>Client</span>";
- }
- }
- $employeeStorage = array();
- while(($row = mysql_fetch_assoc($query2)) != false){
- if(!(in_array($row[0], $employeeStorage))){
- array_push($clientStorage, $row[0]);
- echo "<li><span class='searchName'>" . $row['first_name'] . " " . $row['last_name'] . "</span><span class='label label-info pull-right'>Employee</span></li>";
- $id = $row['id'];
- $query3 = mysql_query("SELECT * FROM `employees` WHERE `user_id` LIKE '$id'");
- while(($row = mysql_fetch_assoc($query3)) != false){
- $id = $row['id'];
- echo "<span class='hidden' id='searchId'>" . $row['id'] . "</span>";
- }
- echo "<span class='hidden' id='type'>Employee</span>";
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment