Searching for an array of strings in an express.js application

My concern is related to working with an array of strings. The specific situation involves:

let search = ["user","country"];

In order to retrieve data from a MySQL database, I am looking to utilize the LIKE operator.

An example of what I am attempting to achieve is shown below:

searchStmnt = `u.u_fullname LIKE "%` + search + `%"`

Unfortunately, the code provided above does not seem to be functional. Any suggestions or guidance on how to successfully accomplish this task would be greatly appreciated.

Answer №1

const filters = ["name", "location"];
const filterStatement = filters.map(item => `p.p_fullinfo LIKE '%${item}%'`).join(" OR ");
console.log(filterStatement);

...or using REGEXP:

const filters = ["name", "location"];
const filterStatement = `p.p_fullinfo REGEXP '(${filters.join("|")})'`;
console.log(filterStatement);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging the power of Redis client within an Express router

I would like to incorporate the use of a redis client in specific endpoints of my application. Here is how my app.js file is currently structured: //app.js const redis = require('redis'); const client = redis.createClient(process.env.REDIS_POR ...

Show all entries belonging to a specific ID on individual rows for each ID using PHP

I have a table generated from inner joins that displays different articles associated with outfit IDs. id_outfit | name | article ---------------------------------------- 56 | one | shoe.png 56 | one | dress.png 56 | one ...

Iterating over an object in a React component

i'm trying to generate an object using iteration like this: opts = [{label:1, value:1}, {label:4, value:4}] the values for this object are coming from an array portArray = [1,4] I'm attempting to do const portArray = [1,4]; return { ...

Ways to continuously refresh the display in AngularJS

There are 2 div elements below, and I need to display only one of them depending on whether the doStuff() function is triggered in the controller when a specific anchor element is clicked. <div ng-controller='myController'> <div ng- ...

The issue of video tags not displaying previews on iPhone across all browsers is also accompanied by problems with controls not functioning correctly

As I delve into the world of HTML5 video tags, I encountered an issue where the video wouldn't show a preview frame initially. Instead, only the Resume button would appear. Furthermore, after playing the video with the Resume button, it wouldn't ...

UI-data contracts: enhancing client-side JSON data validation

I have encountered situations where the JSON data I receive from services and database calls, created by a different team, contains invalid data combinations that lead to unintended errors downstream. For example, in the case below, if the "rowContent" fi ...

"Encountered an issue when attempting to convert undefined or null to an object within a

I am facing an issue with my test setup which looks like this: var jsdom = require('jsdom').jsdom; var document = jsdom('<html></html>', {}); var window = document.defaultView; global.jQuery = global.$ = require('jquer ...

Exploring the advanced features of OpenOffice Draw for improved geometry analysis

Struggling with the draw:enhanced-geometry section that involves draw:enhanced-path and draw:equation. I'm working on an OOo converter but can't seem to find any concrete solutions or extensive documentation about this part. Any suggestions on ho ...

Update state within React components without impacting any other state variables

Imagine I have an object structured like this: person : { name : "Test", surname : "Test", age : 40, salary : 5000 currency : "dollar", currency_sign : "$", . . . } I am looking to achieve the following I will make ...

Having difficulty retrieving information from the columns of the View

Attempting to retrieve information from a MySQL database using SQLAlchemy's reflection feature has hit a snag. Despite reflecting the view successfully, fetching data from it seems to be problematic. dev=DBSession2.execute("select project from myView ...

Issue found in the mysql segment

As a newcomer to android development, I have a website with a mysql database already set up. I am trying to figure out how to connect my app to that database. However, my attempts so far have resulted in an invalid IP address error in the PHP code. Below i ...

Consistently encountering issues when attempting to submit JSON data via POST request (body in raw format

I'm facing an issue with sending data to my server. Currently, I am working on a project using react native and axios version ^0.16.2. let input = { 'longitude': -6.3922782, 'latitude': 106.8268856, 'content': &apos ...

Is there an issue connecting .NET to MySQL using ODBC 5.3?

I am encountering an issue with my ASP.NET webform .NET 4.5 website that utilizes MySQL ODBC to communicate with the MySQL Database. Everything works fine with the 32-bit driver version 5.1.13, but when I upgrade to version 5.3.4, I receive the following e ...

Replicating MySQL across multiple clusters

I am exploring the options for setting up multi-master replication with 4 MySQL servers, and after some research, I have come across two potential solutions: 1) The ring connection method where data flows from Server_1 to Server_2, then Server_3, Server_4 ...

Javascript - Editing specific markers with varying titles from the url

My website contains checkboxes in the html code: <input onclick="markAsChanged(this); toggleApproveDeny(this);" name="2c9923914b887d47014c9b30b1bb37a1_approveChk" type="checkbox"> <input onclick="markAsChanged(this); toggleApproveDeny(this);" na ...

What is the best location for the frontend server code within an application built using create-react-app?

After using create-react-app to create my app, I am looking to log messages in the server console. Any advice on how to achieve this? I attempted adding index.js to the root folder and creating a server folder, but so far it hasn't been successful. ...

Unable to locate my HTML file in the view section

I have been working on setting up a MEAN app and I've encountered an issue. Everything runs smoothly without the Angular part, but as soon as I integrate Angular, I am unable to view the HTML page located in the "view" folder. Here is my server setup ...

Encountering an unexplained JSON error while working with JavaScript

I'm trying to retrieve data from a JSON API server using JavaScript AJAX and display it in an HTML table. However, I keep encountering an undefined error with the data displaying like this: Name id undefined undefined This is my code snippe ...

How to extract column name from query result set using JavaScript in Snowflake database?

When querying in Snowflake with JavaScript inside a stored procedure, we typically receive a Result_set. How can the column names of the output result be retrieved using the JavaScript API? Please note that this inquiry is not about retrieving the values ...

Calculate the total sum of all numerical values within an array of objects

Here's an example of an array: const arr = [{ a: 12, b: "A" c: 17 }, { a: 12, b: "B" c: 17 }, { a: 12, b: "C" c: 17 } ]; What is the most efficient way to calculate the sum of all objects in the array? T ...