The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (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
#12
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 Sad

I do not understand why you put and R and a C behind children in your example though.
  Reply
#13
sorry...this is the correct file: http://pastebin.com/DFWXMenP
  Reply
#14
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?

  Reply
#15
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 Smile

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.
  Reply
#16
How would I go about changing the results (
Code:
echo $found->fname." ".$found->lname."<br>";
) to links to those peoples profiles?

Something like
Code:
<a href="profile.php?id=<?=$v1->id?>">...</a>
  Reply
#17
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>";
  Reply
#18
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>';
it did give me links, but they were all named
Code:
".$found->fname." ".$found->lname."
and they didn't link to the actual profiles.

I have tried a few variations but still no luck though.
Mudmin? Maybe you can shed some light on this?
  Reply
#19
Sorry try this:

Code:
echo "<a href="profile.php?id=".$m.">".$found->fname." ".$found->lname."</a><br>";
  Reply
#20
yeah, that is one of the things I tried too. Doesn't work Sad

It needs to be
Code:
echo '<a href="profile.php?id=".$m.">".$found->fname." ".$found->lname."</a><br>';
to display anything though. Using "" around the whole thing will produce a blank page.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)