Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.98 KB | None | 0 0
  1. <?php
  2. require_once 'users/init.php';
  3. require_once $abs_us_root.$us_url_root.'users/includes/header.php';
  4. require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
  5. ?>
  6. <?php //here is your logic
  7. if(!empty($_POST)){
  8.     $lname = Input::get('user');
  9.     $company = Input::get('company');
  10.  
  11.     if($lname == 1){ //it's getting this from the value of the checkbox
  12.         //if last name box is checked
  13.         $lastname = "user";
  14.         $lnQ=$db->query("SELECT id FROM users WHERE lname = ? ",array($lastname));
  15.         $ln=$lnQ->results();
  16.  
  17.     }
  18.  
  19.     if($company == 1){
  20.         //if last name box is checked
  21.         $companyname = "UserSpice";
  22.         $compQ=$db->query("SELECT id FROM users WHERE company = ? ",array($companyname));
  23.         $comp=$compQ->results();
  24.  
  25.     }
  26.     //now it's time to put this all together
  27.     $matches = []; //Create an empty array
  28.  
  29.     //You only want to run this if the box is checked, so you need to go back to your = 1 statements...
  30.     if($lname == 1){
  31.  
  32.         foreach ($ln as $l){
  33.             array_push($matches,$l); //add each id to the array
  34.         }
  35.     }
  36.  
  37.     if($company == 1){
  38.         //now, only if the id is UNIQUE are we going to add it to the array
  39.         foreach ($comp as $c){
  40.             if (!in_array($c, $matches))
  41.             {
  42.                 $matches[] = $c;
  43.             }
  44.         }
  45.     }
  46.     //if you uncomment the line below, you can see your array
  47.     //dump($matches);
  48.  
  49. }
  50.  
  51. ?>
  52.  
  53. <div id="page-wrapper">
  54.     <div class="container">
  55.         <div class="row">
  56.             <div class="col-xs-12">
  57.                 <div class="jumbotron">
  58.                     <h1>Welcome to UserSpice</h1>
  59.                 </div>
  60.             </div>
  61.         </div>
  62.  
  63.         <div class="row">
  64.             <div class="col-md-12">
  65.  
  66.                 <form class="" action="index.php" method="post">
  67.                     <div class="col-md-2">
  68.                         <label><input type="checkbox" name="user" class="form-control" value="1">Last name is user</label>
  69.                     </div>
  70.                     <div class="col-md-2">
  71.                         <label><input type="checkbox" name="company" class="form-control" value="1">Company is UserSpice</label>
  72.                     </div>
  73.                     <input class='btn btn-danger' type='submit' name='Submit' value='submit' />
  74.                 </form>
  75.                 <?php
  76.                 //See all the logic at the top of the page first!
  77.                 //Now you want go get your users list back.  Let's just echo out the first/last name of each
  78.                 if(!empty($_POST)){
  79.                     echo "<strong>Here's what we found...</strong><br>";
  80.                     if(!empty($matches)){
  81.                         foreach ($matches as $m){
  82.                             $foundQ = $db->query("SELECT * FROM users WHERE id = ?",($m));
  83.                             $found = $foundQ->first();
  84.                             echo $found->fname." ".$found->lname."<br>";
  85.                         }
  86.                     }else{
  87.                         echo "Sorry. No users were found";
  88.                     }
  89.                 }
  90.                 ?>
  91.  
  92.             </div><!-- /.col -->
  93.         </div><!-- /.row -->
  94.  
  95.     </div> <!-- /container -->
  96.  
  97. </div> <!-- /#page-wrapper -->
  98.  
  99. <!-- footers -->
  100. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  101.  
  102. <!-- Place any per-page javascript here -->
  103.  
  104.  
  105. <?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement