The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database search filter
#11
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();
//you could probably just use the $children variable again

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();
//you could probably just use the $children variable again
Code:
foreach ($childrenR as $c){
Code:
if (!in_array($c, $matches)) {
Code:
array_push($matches,$c);
Code:
}
Code:
}
Code:
}
Code:
}
  Reply


Messages In This Thread
Database search filter - by LBC - 01-12-2017, 11:06 AM
Database search filter - by mudmin - 01-12-2017, 01:57 PM
Database search filter - by Brandin - 01-12-2017, 02:44 PM
Database search filter - by LBC - 01-12-2017, 04:19 PM
Database search filter - by mudmin - 01-12-2017, 08:27 PM
Database search filter - by LBC - 01-13-2017, 06:33 AM
Database search filter - by mudmin - 01-13-2017, 02:17 PM
Database search filter - by mudmin - 01-13-2017, 06:43 PM
Database search filter - by meetmec12 - 01-14-2017, 09:42 AM
Database search filter - by LBC - 01-17-2017, 08:11 AM
Database search filter - by mudmin - 01-17-2017, 02:21 PM
Database search filter - by LBC - 01-18-2017, 08:35 AM
Database search filter - by LBC - 01-18-2017, 08:56 AM
Database search filter - by sabr - 01-18-2017, 12:24 PM
Database search filter - by LBC - 01-18-2017, 12:55 PM
Database search filter - by LBC - 01-18-2017, 02:36 PM
Database search filter - by sabr - 01-18-2017, 02:57 PM
Database search filter - by LBC - 01-19-2017, 07:35 AM
Database search filter - by sabr - 01-19-2017, 07:42 AM
Database search filter - by LBC - 01-19-2017, 08:28 AM
Database search filter - by sabr - 01-19-2017, 08:46 AM
Database search filter - by LBC - 01-19-2017, 08:54 AM
Database search filter - by sabr - 01-19-2017, 08:57 AM
Database search filter - by LBC - 01-19-2017, 08:58 AM
Database search filter - by sabr - 01-19-2017, 12:07 PM
Database search filter - by LBC - 01-20-2017, 06:43 AM
Database search filter - by sabr - 01-20-2017, 08:19 AM
Database search filter - by LBC - 01-20-2017, 08:56 AM
Database search filter - by sabr - 01-20-2017, 09:00 AM
Database search filter - by mudmin - 01-20-2017, 03:25 PM
Database search filter - by plb - 01-22-2017, 09:18 PM
Database search filter - by LBC - 01-24-2017, 08:15 AM
Database search filter - by LBC - 01-24-2017, 09:00 AM
Database search filter - by plb - 01-24-2017, 08:43 PM
Database search filter - by LBC - 01-25-2017, 07:06 AM
Database search filter - by LBC - 01-30-2017, 07:16 AM
Database search filter - by mudmin - 02-03-2017, 02:17 PM
Database search filter - by LBC - 02-06-2017, 07:30 AM
Database search filter - by mudmin - 02-07-2017, 03:27 AM
Database search filter - by LBC - 02-07-2017, 06:56 AM
Database search filter - by sabr - 02-07-2017, 08:26 AM
Database search filter - by LBC - 02-07-2017, 09:23 AM
Database search filter - by sabr - 02-07-2017, 09:34 AM
Database search filter - by LBC - 02-07-2017, 09:47 AM
Database search filter - by sabr - 02-07-2017, 07:26 PM
Database search filter - by LBC - 02-08-2017, 08:12 AM
Database search filter - by sabr - 02-08-2017, 11:54 AM

Forum Jump:


Users browsing this thread: 8 Guest(s)