Multiple search from the database [duplicate]

37
March 16, 2019, at 00:20 AM

This question already has an answer here:

  • Mysql search query two columns 3 answers

I have a search bar that finds values from the database, I wanted the search bar to search values from multiple columns.

Here's what I currently have and is working:

$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "SELECT * FROM request WHERE trackingcode LIKE '%".$search."%' ";

I've tried:

$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "SELECT * FROM request WHERE trackingcode, anothercolumn LIKE '%".$search."%' ";

but it didn't work. Am I doing it wrong? (of course lol)

Answer 1

You can't use two columns in a WHERE clause with a comma, you'll have to use an OR operator for that. Something like:

$query ="SELECT * FROM request WHERE trackingcode LIKE '%".$search."%' OR anothercolumn LIKE '%".$search."%'";

Refer to: https://dev.mysql.com/doc/refman/8.0/en/multiple-column-indexes.html

Answer 2

Perhaps try an OR condition:

$query = "select * from request where trackingcode like '%{$search}%' or anothercolumn like '%{$search}%'";
Answer 3

You can use OR operator to solve this issue

$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "SELECT * 
          FROM request  
          WHERE trackingcode LIKE '%".$search."%' 
             OR anothercolumn LIKE '%".$search."%'";
READ ALSO
in laravel 5.8 is its possible to spoof the url bar whit out reloading the page

in laravel 5.8 is its possible to spoof the url bar whit out reloading the page

Is it possible in laravel to spoof an url whit out reloading the page, for example when you have an url like this webpage/post/1 and 1 standing for the id, that you then can make it webpage/post/{Post-Name} whit out using webpage/post/#{Post-Name} whitout...

15
How to set up routing for a php api script create.php?

How to set up routing for a php api script create.php?

I'm trying to setup an url in my laravel project from which my database can receive post requests, i have this script i made in php and i put in /public folder, it works fine when hosted in xampp but when i put it in my laravel project i get a not found error this is what my php script...

16
How to provide website statistics for page visits? [on hold]

How to provide website statistics for page visits? [on hold]

I have a website written in php and mysql, the website also have an admin panel for user interfaceIs there any quick and easy way to provide a website statistics in admin panel?

29
Display selected BACS account from matching order item meta value using Woocommerce hooks

Display selected BACS account from matching order item meta value using Woocommerce hooks

Based on "Select BACS account to show in thankyou page in WooCommerce" answer code to one of my questions, I have changed the Woocommerce core file "class-wc-gateway-bacsphp" In order to select the correct bank account displayed on thankyou page, that matches...

38