The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Database search filter - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: Database search filter (/showthread.php?tid=424) |
Database search filter - mudmin - 01-17-2017 The first thing that stands out is that you're replacing your queries. So, for instance in this section... Code: if($something == 1){ Code: //if last name box is checked Code: $something = "something"; Code: $compQ=$db->query("SELECT id FROM users WHERE something = ? ",array($something)); Code: $comp=$compQ->results(); Code: } Code: if($children == 1){ Code: //if last name box is checked Code: $children = "children"; Code: $compQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children)); Code: $comp=$compQ->results(); Code: } if both children and something are selected, it will fire off the something query (using the $compQ variable) and get the results with the $comp variable and then once it sees that children are selected, it will flush out those two variables with the results from children. So give each one its own variable name. I like being super consistent like... Code: if($children == 1){ Code: //if last name box is checked Code: $children = "children"; Code: $childrenQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children)); Code: $childrenR=$childrenQ->results(); Code: } Also, since you already have your if statements for each query, you can go ahead and feel free to pop in your foreach there and get rid of the one below. . So that would look like. I would also put in a check here to make sure you got a result. So, what you can do, is count the number of rows you got back. This will stop it from throwing errors in the event you didn't get any results. Code: if($children == 1){ Code: //if last name box is checked Code: $children = "children"; Code: $childrenQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children)); Code: $childrenC=$childrenQ->count(); Code: if($childrenC > 0){ //only fire off the rest of this if you got any results from your query Code: $childrenR=$childrenQ->results(); Code: foreach ($childrenR as $c){ Code: if (!in_array($c, $matches)) { Code: array_push($matches,$c); Code: } Code: } Code: } Code: } Database search filter - LBC - 01-18-2017 Hmmm...there are some things I don't understand. I now have this: http://pastebin.com/m0VPYjSs But now it's not giving any results at all anymore I do not understand why you put and R and a C behind children in your example though. Database search filter - LBC - 01-18-2017 sorry...this is the correct file: http://pastebin.com/DFWXMenP Database search filter - sabr - 01-18-2017 http://pastebin.com/wtN17RJb // Minor code reshuffle to save jumping around the page. @LBC how are you storing these values in the database? You mentioned all interests have individual columns, so are they boolean values? Database search filter - LBC - 01-18-2017 Hello sabr, Oh wow! Seems to be working now! Thank you for having a look! The columns are each named after the interest, and the data stored in them is just text (so if selected during the registering process column small_animals is storing the words small animals, column environment stores the word environment). I don't know if that is boolean or not...I am learning (very veeeeery slowly as I go along I chose to have words in there (instead of yes/no or 0/1) because of people have to be able to search for them using search words. Database search filter - LBC - 01-18-2017 How would I go about changing the results ( Code: echo $found->fname." ".$found->lname."<br>"; Something like Code: <a href="profile.php?id=<?=$v1->id?>">...</a> Database search filter - sabr - 01-18-2017 I believe something like this should work: Code: <a href="profile.php?id=<?=$found;?>"><?=$found->fname." ".$found->lname;?></a><br> or as if you are staying within the if statement then it would be: Code: echo "<a href="profile.php?id=".$found.">".$found->fname." ".$found->lname."</a><br>"; Database search filter - LBC - 01-19-2017 Hmm, nope that's not working I'm afraid. I got a blank page when I used those codes. After I changed it to Code: echo '<a href="profile.php?id=.$found.">".$found->fname." ".$found->lname."</a><br>'; Code: ".$found->fname." ".$found->lname." I have tried a few variations but still no luck though. Mudmin? Maybe you can shed some light on this? Database search filter - sabr - 01-19-2017 Sorry try this: Code: echo "<a href="profile.php?id=".$m.">".$found->fname." ".$found->lname."</a><br>"; Database search filter - LBC - 01-19-2017 yeah, that is one of the things I tried too. Doesn't work It needs to be Code: echo '<a href="profile.php?id=".$m.">".$found->fname." ".$found->lname."</a><br>'; |