Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'users/init.php';
- require_once $abs_us_root.$us_url_root.'users/includes/header.php';
- require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
- ?>
- <?php //here is your logic
- if(!empty($_POST)){
- $lname = Input::get('user');
- $company = Input::get('company');
- if($lname == 1){ //it's getting this from the value of the checkbox
- //if last name box is checked
- $lastname = "user";
- $lnQ=$db->query("SELECT id FROM users WHERE lname = ? ",array($lastname));
- $ln=$lnQ->results();
- }
- if($company == 1){
- //if last name box is checked
- $companyname = "UserSpice";
- $compQ=$db->query("SELECT id FROM users WHERE company = ? ",array($companyname));
- $comp=$compQ->results();
- }
- //now it's time to put this all together
- $matches = []; //Create an empty array
- //You only want to run this if the box is checked, so you need to go back to your = 1 statements...
- if($lname == 1){
- foreach ($ln as $l){
- array_push($matches,$l); //add each id to the array
- }
- }
- if($company == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($comp as $c){
- if (!in_array($c, $matches))
- {
- $matches[] = $c;
- }
- }
- }
- //if you uncomment the line below, you can see your array
- //dump($matches);
- }
- ?>
- <div id="page-wrapper">
- <div class="container">
- <div class="row">
- <div class="col-xs-12">
- <div class="jumbotron">
- <h1>Welcome to UserSpice</h1>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12">
- <form class="" action="index.php" method="post">
- <div class="col-md-2">
- <label><input type="checkbox" name="user" class="form-control" value="1">Last name is user</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="company" class="form-control" value="1">Company is UserSpice</label>
- </div>
- <input class='btn btn-danger' type='submit' name='Submit' value='submit' />
- </form>
- <?php
- //See all the logic at the top of the page first!
- //Now you want go get your users list back. Let's just echo out the first/last name of each
- if(!empty($_POST)){
- echo "<strong>Here's what we found...</strong><br>";
- if(!empty($matches)){
- foreach ($matches as $m){
- $foundQ = $db->query("SELECT * FROM users WHERE id = ?",($m));
- $found = $foundQ->first();
- echo $found->fname." ".$found->lname."<br>";
- }
- }else{
- echo "Sorry. No users were found";
- }
- }
- ?>
- </div><!-- /.col -->
- </div><!-- /.row -->
- </div> <!-- /container -->
- </div> <!-- /#page-wrapper -->
- <!-- footers -->
- <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
- <!-- Place any per-page javascript here -->
- <?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