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)){
- $small_animals = Input::get('small_animals');
- $large_animals = Input::get('large_animals');
- $animal_habitat = Input::get('animal_habitat');
- $environment = Input::get('environment');
- $habitat = Input::get('habitat');
- $something = Input::get('something');
- $children = Input::get('children');
- $elderly = Input::get('elderly');
- $disabled = Input::get('disabled');
- $homeless = Input::get('homeless');
- if($small_animals == 1){ //it's getting this from the value of the checkbox
- //if last name box is checked
- $smallanimals = "small animals";
- $small_animalsQ=$db->query("SELECT id FROM users WHERE small_animals = ? ",array($smallanimals));
- $small_animals=$small_animalsQ->results();
- }
- if($large_animals == 1){
- //if last name box is checked
- $largeanimals = "large animals";
- $large_animalsQ=$db->query("SELECT id FROM users WHERE large_animals = ? ",array($largeanimals));
- $large_animals=$large_animalsQ->results();
- }
- if($animal_habitat == 1){
- //if last name box is checked
- $animalhabitat = "animal habitat";
- $animal_habitatQ=$db->query("SELECT id FROM users WHERE animal_habitat = ? ",array($animalhabitat));
- $animal_habitat=$animal_habitatQ->results();
- }
- if($environment == 1){
- //if last name box is checked
- $environment = "environment";
- $environmentQ=$db->query("SELECT id FROM users WHERE environment = ? ",array($environment));
- $environment=$environmentQ->results();
- }
- if($habitat == 1){
- //if last name box is checked
- $habitat = "habitat";
- $habitatQ=$db->query("SELECT id FROM users WHERE habitat = ? ",array($habitat));
- $habitat=$habitatQ->results();
- }
- if($something == 1){
- //if last name box is checked
- $something = "something";
- $somethinQ=$db->query("SELECT id FROM users WHERE something = ? ",array($something));
- $something=$somethinQ->results();
- }
- if($children == 1){
- //if last name box is checked
- $children = "children";
- $childrenQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children));
- $children=$childrenQ->results();
- }
- if($elderly == 1){
- //if last name box is checked
- $elderly = "elderly";
- $elderlyQ=$db->query("SELECT id FROM users WHERE elderly = ? ",array($elderly));
- $elderly=$elderlyQ->results();
- }
- if($disabled == 1){
- //if last name box is checked
- $disabled = "disabled";
- $disabledQ=$db->query("SELECT id FROM users WHERE disabled = ? ",array($disabled));
- $disabled=$disabledQ->results();
- }
- if($homeless == 1){
- //if last name box is checked
- $homeless = "homeless";
- $homelessQ=$db->query("SELECT id FROM users WHERE homeless = ? ",array($homeless));
- $homeless=$homelessQ->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($small_animals == 1){
- foreach ($ln as $l){
- array_push($matches,$l); //add each id to the array
- }
- }
- if($large_animals == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($large_animals as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($animal_habitat == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($animal_habitat as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($environment == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($environment as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($habitat == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($habitat as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($something == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($something as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($children == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($children as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($elderly == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($elderly as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($disabled == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($disabled as $c){
- if (!in_array($c, $matches))
- {
- array_push($matches,$c);
- }
- }
- }
- if($homeless == 1){
- //now, only if the id is UNIQUE are we going to add it to the array
- foreach ($homeless as $c){
- if (!in_array($c, $matches))
- {
- array_push($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="cbsearch.php" method="post">
- <div class="col-md-2">
- <label><input type="checkbox" name="small animals" class="form-control" value="1">Small animals</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="large animals" class="form-control" value="1">Large animals</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="animal habitat" class="form-control" value="1">Animal habitat</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="environment" class="form-control" value="1">Environment</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="habitat" class="form-control" value="1">Habitat</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="something" class="form-control" value="1">Something</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="children" class="form-control" value="1">Children</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="elderly" class="form-control" value="1">Elderly</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="disabled" class="form-control" value="1">Disabled</label>
- </div>
- <div class="col-md-2">
- <label><input type="checkbox" name="homeless" class="form-control" value="1">Homeless</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