Guest User

Untitled

a guest
Dec 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2. require_once 'connect.php';
  3. if(isset($_POST['search_term']) == true && empty($_POST['search_term'])==false){
  4.  
  5. $search_term = mysql_real_escape_string(trim($_POST['search_term']));
  6. $terms = explode(" ", $search_term);
  7.  
  8. foreach ($terms as $term) {
  9. $query = mysql_query("SELECT * FROM `clients` WHERE `last_name` LIKE '$term%' OR `first_name` LIKE '$term%' OR `company` LIKE '$term%' LIMIT 3");
  10. $query2 = mysql_query("SELECT * FROM `users` WHERE `last_name` LIKE '$term%' OR `first_name` LIKE '$term%' LIMIT 3");
  11.  
  12. $emps = array(); // TO HOLD THE EMPLOYEES WHO MATCH
  13. $clients = array(); // TO HOLD THE CLIENTS WHO MATCH
  14.  
  15. $clientStorage = array();
  16. while(($row = mysql_fetch_assoc($query)) != false){
  17.  
  18. //if the client id is not in the array clientStorage then
  19. //the client is unique, now we must
  20. // add this clients id to to clientStorage
  21. if(!(in_array($row[0], $clientStorage))){
  22. array_push($clientStorage, $row[0]);
  23. // PRINT OUT THE SEARCH RESULT
  24. echo "<li><span class='searchName'>" . $row['first_name'] . " " . $row['last_name'] . "</span><span class='label pull-right'>Client</span>";
  25. if(!empty($row['company'])){
  26. echo "<br><p class='noMargin'><small><em>" . $row['company'] . "</em></small></p>";
  27. }
  28. echo "</li>";
  29. echo "<span class='hidden' id='searchId'>" . $row['id'] . "</span>";
  30. echo "<span class='hidden' id='type'>Client</span>";
  31. }
  32. }
  33. $employeeStorage = array();
  34. while(($row = mysql_fetch_assoc($query2)) != false){
  35. if(!(in_array($row[0], $employeeStorage))){
  36. array_push($clientStorage, $row[0]);
  37. echo "<li><span class='searchName'>" . $row['first_name'] . " " . $row['last_name'] . "</span><span class='label label-info pull-right'>Employee</span></li>";
  38. $id = $row['id'];
  39.  
  40. $query3 = mysql_query("SELECT * FROM `employees` WHERE `user_id` LIKE '$id'");
  41.  
  42. while(($row = mysql_fetch_assoc($query3)) != false){
  43. $id = $row['id'];
  44. echo "<span class='hidden' id='searchId'>" . $row['id'] . "</span>";
  45. }
  46. echo "<span class='hidden' id='type'>Employee</span>";
  47. }
  48. }
  49. }
  50. ?>
Add Comment
Please, Sign In to add comment