Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!empty($_POST)){
- $sql = 'SELECT * FROM users WHERE 1 = 2'; // if no interests chosen, don't return anything
- foreach (['small_animals', 'large_animals', 'animal_habitat', 'environment, ...] as $var) {
- $inp = Input::get($var);
- if ($inp == 1) {
- $val = str_replace('_', ' ', $var);
- // since your code has the values hard-coded there's no need to bind it - no security risk of injection or etc
- $sql .= " OR ($var = '$var')";
- }
- }
- // now $sql contains a full query like "SELECT * FROM users WHERE 1 = 2 OR (homeless = 'homeless') OR (environment = 'environment')
- $sql = "SELECT * FROM users $where";
- $interested_users = $db=>query($sql)=>results();
- }
- // I skipped the rest of the HTML and etc code - this is the loop that you had to display the results:
- /*
- 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";
- }
- }
- */
- // I replaced it with this:
- if (!empty($_POST)) {
- echo "here's what we found";
- foreach ($interested_users as $result) {
- echo $result->fname.' '.$result->lname.'<br />';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement