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
#1
I'm trying to create a form with multiple checkboxes through which someone can search the database (by checking certain boxes).

So, checking box 1, 4, and 5 will display a result of users that have the corresponding data in their profile.

Does this make sense and is there a way to do this within UserSpice?
  Reply
#2
I have some ideas but give me a little bit more info. Like...

1. Are you always searching the same table (like the users table)
2. Are these results filtering (an example of this would be you search your entire database and checkbox 1 is male, checkbox 4 is over 18, checkbox 5 is "has signed in with Google".

So when you run your query, do you ONLY want to know the users who have done all three, or do you want a list of users who have done any of the 3?
  Reply
#3
This sounds interesting and sounds like a good deploy! Another example could be:
I have a database pull that displays all of my orders, and I have the statuses as checkboxes. So if I check box 1 (Shipped) 4 (Returned) and 5 (Lost), it will show all orders with that status.

I'm excited!
  Reply
#4
Yes, I'd like to search the users table. And yes it is filtering...and yes I want to display users who have done any of the three Smile

It's like this:

My users select their interests when they sign up (for instance red, green and blue). This data gets stored with their profile in the DB (in seperate columns. So a column for red, one for green one for blue, etc.).

I want other users to be able to check boxes on a form and send it (like a search query). So a user can check the box for green and red and than all the users who have that in their profile will be displayed.

I have a search form already but it lacks the ability to do some stuff I want. As I have two kinds of users and only want one kind displayed in the search.

I added two columns in the users table (lets say user1 and user2) and give them a value when people sign up (1 for yes or 0 for no). But when I add that to my search query SELECT something, something FROM users WHEN user1='1'; username '{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}" . etc...it does only display the profiles of the user1 people...but that is the only thing it will do. It doesnt respond to other inputs like username, country or city. It only diplays user1 profiles no matter what words you enter into the search field.

I thought I could bypass all this by having people check some boxes with possible search terms so they can in effect only search for stuff I want them to search for.

I'm not sure of im making any sense at all though :p
  Reply
#5
You're making sense. I just have to go back to some of my array logic and write some code or you can take a crack at it.

The gist of what I would do is for each checkbox that is checked, query the database for the id column WHERE color = red and then add that id to an array called $found (or something like that).

Then when you run your next query, only add the unique user id's to the array. (so you get an array of the user id of each user who was found once and only once).

Then you will do a foreach loop and query the users table for each user by id.

If you need help with the specific code, let me know and I can work something up.
  Reply
#6
hehe...yeah, sure I'll take a crack at it. I'm pretty sure it won't get me anywhere though.
So, if you have time please do try to write something too...and we will compare notes Wink

  Reply
#7
Ok. Here you go. Let me give you some context. I did this on an install with 3 users. Users 1 and 2 had the last name of "user". Users 1 and 3 had a company of "UserSpice". This let me get a different data set depending on which of the two checkboxes I checked. You can give it a shot. I have this file set to be index.php in your root. If you change the location, make sure to change the form action.

http://pastebin.com/pzkNrnzH

Let me know what you think
  Reply
#8
I just realized that if your results don't work when you add more checkboxes, you can change the second set of logic from

Code:
foreach ($comp as $c){
Code:
if (!in_array($c, $matches))
Code:
{
Code:
$matches[] = $c;
Code:
}

to
Code:
foreach ($comp as $c){
Code:
if (!in_array($c, $matches))
Code:
{
Code:
array_push($matches,$c);
Code:
}

Note that as you add your 3rd (and beyond) checkbox, use the second set of logic where you are saying if !in_array so you don't get duplicates in your array).
  Reply
#9
This could help get an open source data management that creates php sites in mins . disable security in the projecr .copy the project folder to your US site .follow new folder protection in US . done.
  Reply
#10
Hello Mudmin,

sorry for the late response. Thank you so much for having a look at this!
Everything seems to be working...until I add more checkboxes.

I have added several more checkboxes and have changed the second one and the next 8 to
Code:
array_push($matches,$c);
like you suggested.

However, after I had done that it now only shows results for the first three boxes, but not the rest.

Here is my file: http://pastebin.com/9rCCAjp0

Any ideas?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)