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
Search function
#1
Hi guys, I desperately need a good working (secure against sql-injections) search function so my users can search the database for other users.

It would be SO great if that could be implemented soon Smile

Or, if anyone reading this has a clue how to implement it in User Spice and would be so kind as to tell me about it. That would be awesome!
  Reply
#2
I have a quick way you can do it....

There is already a view_all_users page that I think is set to private. You could make that so all user groups could see it. Next, you can decide to share more informaiton to that table (whatever you want to be searchable I guess). Then you can use the search function we have built into admin_pages (it's super simple) to "filter" all of the users you have. Would that work?

  Reply
#3
Hey mudmin, the filter function is not really an option as it would show all the users in the database to the person that did the "search". That could potentially be thousands of records that would be shown.

I just need a simple search query echoeing the results on the same page. Like...type in a country, and all the users from that country would be listed below the search bar.
  Reply
#4
I love UserSpice and all its features, but my being able to use it for my project absolutely hinges on that search-function.

It is probably not all that difficult to put together, but I personaly have NO clue how to get it to work. I have been trying for days now, to no avail.

I am not adept at coding at all. I mostly just copy/paste codes used elsewhere and see if it works. It is the way I learn and it mostly works fine for me.

But this search function just totally baffles me. The "normal" ways of searching a database just dont seem to apply here. I think it might have to do with a missing function in the us_helpers.php file or something (at least thats all I can come up with).

So, I ask again, please...is there anyone out there able and willing to help me out here? It would be SO much appreciated. My project is just completely on its ass now because of this Sad
  Reply
#5
Can you give me an idea of what needs to be searched?

Like if I put the word Dan in a search box, what parts of the db do you want it to look in?

I am also confused why the normal search methods don't work. US uses a completely standard db.
  Reply
#6
Hello Dan. Thank you for your response.

I only need the users table to be searched (by registered members). I have added country and city to that, and what I need is when someone types in France that all the users from France are displayed. Or when someone types in New York, that all the users from NY are displayed.

Thats it really.

As I mentioned my coding skills are rather mediocre at best so i could well be missing something very simple.

I think I just dont know what names have been given to certain functions or what have you, so I dont know what to change in the search form codes I copy from other places (as I mentioned my coding consists of copy/pasting pieces of coding I find on different sites and tutorials).

Now if i could only get the search bar to look in the users table and display the results (without showing every single user and then just filter out the ones matching the query), than I'm sure I coukd pick up from there ?
  Reply
#7
I have a few ideas... I am not in front of my computer, but I will definitely look at that over the next day or two. Don't stress out about that part do the rest of what you need to do. I can make that work.

  Reply
#8
You are awesome ?
  Reply
#9
So this is a pretty detailed walkthrough on how to make a search function....
http://www.webreference.com/programming/...index.html

The only real difference is that you have to combine it with the UserSpice db class.

On the second page where it says //connect to the database, you can just use

Code:
$db = DB::getInstance();

And you only have to do that once per page.

Then your query looks a little different. You do something like this...

Code:
$x=$_POST['x'];
Code:
$query = $db->query("SELECT * FROM users WHERE username = ?", array($x));

I can help you with the exact queries you need if you get stuck. The big difference is instead of doing
Code:
$sql =""
you do
Code:
$query = $db->query("")

I need to do some refomatting on the page, but you should definitely check out the instructions on the db class.
http://userspice.org/documentation-db-class-2/
  Reply
#10
Thank you mudmin! I will try my hand at this Smile
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)