Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.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. $small_animals = Input::get('small_animals');
  9. $large_animals = Input::get('large_animals');
  10. $animal_habitat = Input::get('animal_habitat');
  11. $environment = Input::get('environment');
  12. $habitat = Input::get('habitat');
  13. $something = Input::get('something');
  14. $children = Input::get('children');
  15. $elderly = Input::get('elderly');
  16. $disabled = Input::get('disabled');
  17. $homeless = Input::get('homeless');
  18.  
  19. if($small_animals == 1){ //it's getting this from the value of the checkbox
  20. //if last name box is checked
  21. $smallanimals = "small animals";
  22. $lnQ=$db->query("SELECT id FROM users WHERE small_animals = ? ",array($smallanimals));
  23. $ln=$lnQ->results();
  24.  
  25. }
  26.  
  27. if($large_animals == 1){
  28. //if last name box is checked
  29. $largeanimals = "large animals";
  30. $compQ=$db->query("SELECT id FROM users WHERE large_animals = ? ",array($largeanimals));
  31. $comp=$compQ->results();
  32.  
  33. }
  34.  
  35. if($animal_habitat == 1){
  36. //if last name box is checked
  37. $animalhabitat = "animal habitat";
  38. $compQ=$db->query("SELECT id FROM users WHERE animal_habitat = ? ",array($animalhabitat));
  39. $comp=$compQ->results();
  40.  
  41. }
  42.  
  43. if($environment == 1){
  44. //if last name box is checked
  45. $environment = "environment";
  46. $compQ=$db->query("SELECT id FROM users WHERE environment = ? ",array($environment));
  47. $comp=$compQ->results();
  48.  
  49. }
  50.  
  51. if($habitat == 1){
  52. //if last name box is checked
  53. $habitat = "habitat";
  54. $compQ=$db->query("SELECT id FROM users WHERE habitat = ? ",array($habitat));
  55. $comp=$compQ->results();
  56.  
  57. }
  58.  
  59. if($something == 1){
  60. //if last name box is checked
  61. $something = "something";
  62. $compQ=$db->query("SELECT id FROM users WHERE something = ? ",array($something));
  63. $comp=$compQ->results();
  64.  
  65. }
  66.  
  67. if($children == 1){
  68. //if last name box is checked
  69. $children = "children";
  70. $compQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children));
  71. $comp=$compQ->results();
  72.  
  73. }
  74.  
  75. if($elderly == 1){
  76. //if last name box is checked
  77. $elderly = "elderly";
  78. $compQ=$db->query("SELECT id FROM users WHERE elderly = ? ",array($elderly));
  79. $comp=$compQ->results();
  80.  
  81. }
  82.  
  83. if($disabled == 1){
  84. //if last name box is checked
  85. $disabled = "disabled";
  86. $compQ=$db->query("SELECT id FROM users WHERE disabled = ? ",array($disabled));
  87. $comp=$compQ->results();
  88.  
  89. }
  90.  
  91. if($homeless == 1){
  92. //if last name box is checked
  93. $homeless = "homeless";
  94. $compQ=$db->query("SELECT id FROM users WHERE homeless = ? ",array($homeless));
  95. $comp=$compQ->results();
  96.  
  97. }
  98. //now it's time to put this all together
  99. $matches = []; //Create an empty array
  100.  
  101. //You only want to run this if the box is checked, so you need to go back to your = 1 statements...
  102. if($small_animals == 1){
  103.  
  104. foreach ($ln as $l){
  105. array_push($matches,$l); //add each id to the array
  106. }
  107. }
  108.  
  109. if($large_animals == 1){
  110. //now, only if the id is UNIQUE are we going to add it to the array
  111. foreach ($comp as $c){
  112. if (!in_array($c, $matches))
  113. {
  114. array_push($matches,$c);
  115. }
  116. }
  117. }
  118.  
  119. if($animal_habitat == 1){
  120. //now, only if the id is UNIQUE are we going to add it to the array
  121. foreach ($comp as $c){
  122. if (!in_array($c, $matches))
  123. {
  124. array_push($matches,$c);
  125. }
  126. }
  127. }
  128.  
  129. if($environment == 1){
  130. //now, only if the id is UNIQUE are we going to add it to the array
  131. foreach ($comp as $c){
  132. if (!in_array($c, $matches))
  133. {
  134. array_push($matches,$c);
  135. }
  136. }
  137. }
  138.  
  139. if($habitat == 1){
  140. //now, only if the id is UNIQUE are we going to add it to the array
  141. foreach ($comp as $c){
  142. if (!in_array($c, $matches))
  143. {
  144. array_push($matches,$c);
  145. }
  146. }
  147. }
  148.  
  149. if($something == 1){
  150. //now, only if the id is UNIQUE are we going to add it to the array
  151. foreach ($comp as $c){
  152. if (!in_array($c, $matches))
  153. {
  154. array_push($matches,$c);
  155. }
  156. }
  157. }
  158.  
  159. if($children == 1){
  160. //now, only if the id is UNIQUE are we going to add it to the array
  161. foreach ($comp as $c){
  162. if (!in_array($c, $matches))
  163. {
  164. array_push($matches,$c);
  165. }
  166. }
  167. }
  168.  
  169. if($elderly == 1){
  170. //now, only if the id is UNIQUE are we going to add it to the array
  171. foreach ($comp as $c){
  172. if (!in_array($c, $matches))
  173. {
  174. array_push($matches,$c);
  175. }
  176. }
  177. }
  178.  
  179. if($disabled == 1){
  180. //now, only if the id is UNIQUE are we going to add it to the array
  181. foreach ($comp as $c){
  182. if (!in_array($c, $matches))
  183. {
  184. array_push($matches,$c);
  185. }
  186. }
  187. }
  188.  
  189. if($homeless == 1){
  190. //now, only if the id is UNIQUE are we going to add it to the array
  191. foreach ($comp as $c){
  192. if (!in_array($c, $matches))
  193. {
  194. array_push($matches,$c);
  195. }
  196. }
  197. }
  198. //if you uncomment the line below, you can see your array
  199. //dump($matches);
  200.  
  201. }
  202.  
  203. ?>
  204.  
  205. <div id="page-wrapper">
  206. <div class="container">
  207. <div class="row">
  208. <div class="col-xs-12">
  209. <div class="jumbotron">
  210. <h1>Welcome to UserSpice</h1>
  211. </div>
  212. </div>
  213. </div>
  214.  
  215. <div class="row">
  216. <div class="col-md-12">
  217.  
  218. <form class="" action="cbsearch.php" method="post">
  219. <div class="col-md-2">
  220. <label><input type="checkbox" name="small animals" class="form-control" value="1">Small animals</label>
  221. </div>
  222. <div class="col-md-2">
  223. <label><input type="checkbox" name="large animals" class="form-control" value="1">Large animals</label>
  224. </div>
  225. <div class="col-md-2">
  226. <label><input type="checkbox" name="animal habitat" class="form-control" value="1">Animal habitat</label>
  227. </div>
  228. <div class="col-md-2">
  229. <label><input type="checkbox" name="environment" class="form-control" value="1">Environment</label>
  230. </div>
  231. <div class="col-md-2">
  232. <label><input type="checkbox" name="habitat" class="form-control" value="1">Habitat</label>
  233. </div>
  234. <div class="col-md-2">
  235. <label><input type="checkbox" name="something" class="form-control" value="1">Something</label>
  236. </div>
  237. <div class="col-md-2">
  238. <label><input type="checkbox" name="children" class="form-control" value="1">Children</label>
  239. </div>
  240. <div class="col-md-2">
  241. <label><input type="checkbox" name="elderly" class="form-control" value="1">Elderly</label>
  242. </div>
  243. <div class="col-md-2">
  244. <label><input type="checkbox" name="disabled" class="form-control" value="1">Disabled</label>
  245. </div>
  246. <div class="col-md-2">
  247. <label><input type="checkbox" name="homeless" class="form-control" value="1">Homeless</label>
  248. </div>
  249. <input class='btn btn-danger' type='submit' name='Submit' value='submit' />
  250. </form>
  251. <?php
  252. //See all the logic at the top of the page first!
  253. //Now you want go get your users list back. Let's just echo out the first/last name of each
  254. if(!empty($_POST)){
  255. echo "<strong>Here's what we found...</strong><br>";
  256. if(!empty($matches)){
  257. foreach ($matches as $m){
  258. $foundQ = $db->query("SELECT * FROM users WHERE id = ?",($m));
  259. $found = $foundQ->first();
  260. echo $found->fname." ".$found->lname."<br>";
  261. }
  262. }else{
  263. echo "Sorry. No users were found";
  264. }
  265. }
  266. ?>
  267.  
  268. </div><!-- /.col -->
  269. </div><!-- /.row -->
  270.  
  271. </div> <!-- /container -->
  272.  
  273. </div> <!-- /#page-wrapper -->
  274.  
  275. <!-- footers -->
  276. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  277.  
  278. <!-- Place any per-page javascript here -->
  279.  
  280.  
  281. <?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