Utilizing AJAX to determine if a specific phrase includes the queried terms

Currently, I am working on an AJAX search bar. At the moment, it only allows me to search for exact words in my table.

ID|Skillset|Description|
1|game|i love game
2|photography|i love to take photo
3|game|game is my forte

My current query searches for exact word matches in the database using PHP:

PHP

$sql = "SELECT userdatafiles.UserID,Name,Link,Title FROM userdatafiles JOIN users ON userdatafiles.UserID = users.UserID WHERE Skillsets = '$searchBar' GROUP BY UserID ORDER BY RAND()";

When a user types 'game', for example, the search will display all skillsets that match 'game'.

However, I want to enhance this by searching not just the Skillset column, but also the Description column. Instead of requiring exact matches, I would like users to be able to type something like 'gam' and have it search both Skillset and Description columns. For instance, if there are words like 'game' or 'i love game', which contain 'gam', they should be displayed as results. Any suggestions on how I can achieve this?

Answer №1

For comparing and selecting your field search, it is recommended to use LIKE and CONCAT respectively:

$sql = "SELECT userdatafiles.UserID, Name, Link, Title 
FROM userdatafiles ud JOIN users u ON userdatafiles.UserID = users.UserID 
WHERE concat(ud.Skillsets, ud.description) LIKE '%$searchBar%' 
GROUP BY UserID ORDER BY RAND()";

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

How can I retrieve the 15th minute of the following hour from a specified time using PHP?

Can you find the time of the next hour's 15th minute from a given time? For example: If the input is 2021-08-26 12:00:37, the output should be 2021-08-26 12:15:00 If the input is 2021-08-26 12:30:37, the output should be 2021-08-26 13:15:00 ...

Tips for uploading a file with an Ajax request in Rails version 2.3

I have a Ruby on Rails 2.3 application where I am facing an issue with uploading files using Ajax requests. When I submit the form with file content, I encounter an error "Error: NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype ...

`Disappointing Outcome: Spring MVC - Ajax file upload fails to function`

I'm having trouble dynamically uploading a file using AJAX and Spring MVC. Here is the approach I am taking: JavaScript function: function initializeQwacCertificate(){ $('#qwac').on('change', function(){ var formData = n ...

Adjusting the thickness of the CSS cursor line upon entering an input field

Having an image as the background for an input field has been causing issues for me. Although I can adjust the line-height and font-size easily, the cursor line appears outside of the background image when clicking inside the input field. Is there a speci ...

Bug Alert: Incompatibility between Angular $resource and PHP causing issues with Update and Delete functionalities

As a newcomer to both AngularJS and PHP, I have been struggling to find comprehensive documentation on using $resource to update records in a database. While I did come across a helpful tutorial here that covers most aspects of $resource usage, I am having ...

Mastering Dependency Injection for League Flysystem Integration

The goal is to develop a unique Reader class that functions as a wrapper for the League Flysystem documentation The purpose of the Reader is to provide a convenient way of reading all files in a directory, regardless of their physical form (local file or ...

Set the value received from the AJAX call as a global integer variable

I'm currently facing an issue in my code and struggling to find the error. I have an ajax call that executes an insert statement and returns the ID of the inserted data successfully. However, my goal is to create a global variable for this ID so that ...

Using Ajax/jQuery in combination with Mongodb

My experience with Ajax/jQuery is fairly new. I am currently working on creating a sample HTML page using Ajax/jQuery to retrieve all customers and search for a customer by ID. Each customer has three variables: ID, firstName, and lastName. I am looking t ...

Is there a way for me to adjust my for loop so that it showcases my dynamic divs in a bootstrap col-md-6 grid layout?

Currently, the JSON data is appended to a wrapper, but the output shows 10 sections with 10 rows instead of having all divs nested inside one section tag and separated into 5 rows. I can see the dynamically created elements when inspecting the page, but th ...

"Troubleshooting issues with retrieving data from database using Ajax and

Help needed! I'm facing issues with a select code while using ajax. The codes seem to be incorrect and not working as intended. Here is the snippet of the problematic code: <?php require_once 'config/dbconfig.php'; if (isset($_REQUE ...

The WHERE NOT IN statement doesn't function in PHP, but it is effective in SQL queries

Trying to extract specific values from one table that are not present in another table poses a challenge. This is the SQL query used: SELECT `u882219588_data`.`user`.`user_name`, `u882219588_data`.`user`.`email`, `u882219588_data`.`user`.`name` FR ...

PHP: Dynamically update div content upon submission

I am attempting to update the "refresh" div after clicking the Submit button and also at regular intervals of 5 seconds. Despite looking through various resources, I have not been able to find a solution that meets my requirements. <script src="h ...

Conflicts between Bootstrap Validator and Ajax.BeginForm in Partial Views of MVC

My current issue involves using Ajax.BeginForm to post data on a form without refreshing the entire page. The goal is to validate a textbox - if it has a value, then the data should be posted; otherwise, a validation message should be displayed. However, I ...

What is causing my Django pagination to continuously display the same items over and over again without change?

I am currently working on implementing an infinite scroll feature using Django and AJAX on my website. The goal is to dynamically load more items from the database when a user reaches the bottom of the page. While everything seems to be functioning correct ...

Alter information within jQuery AJAX success function

A sample function is provided below: jQuery.ajax({ type: "POST", url: jQuery("#exam_form").attr( 'action' ), data: jQuery("#exam_form").serialize(), success: function(result){ //Add row table.append(result); ...

jQuery: Implementing a function for all elements, including those dynamically loaded through Ajax later on

I have implemented a jQuery function to resize text areas, but I need it to work on all text areas. The function works well for existing text areas: $(document.ready(function(){$("text_area").resizer('250px')}); However, it fails to resize tex ...

PHP cURL Facebook Messenger bot for sending messages

For the last few days, I have been experimenting with the Facebook Messenger Platform and encountering a problem. PHP has been the main language used. So far, I have managed to incorporate a couple of APIs into the system, mainly dealing with plain text. ...

Challenges with integrating Wampserver PHP 5.3.1 and Pear:DB

After successfully installing PHP5.3.1 on top of 5.3.0 on my Windows 7 Pro laptop, along with Smarty, Pear and relevant Pear packages, I have encountered a strange issue. I have separate development and production sites set up using a config.php file - the ...

Bug in data parsing process

Check out this code snippet: $_REQUEST[ 'LOM' ] var_dump($_REQUEST[ 'LOM' ]); After running the code, the output shows a JSON structure like this: { "id":0, "type":"root", "related_dropzone_id":0, "related_dropzone_order" ...

Updating template views in Grails without the use of ajax enables seamless and dynamic

In my GSP template, I am looking to provide the user with updates on the progress of a task within an overlay. Once the user submits their data, the controller triggers a service to carry out the task. Simultaneously, another service calculates the percen ...