Make a Dropdown with Search Box using jQuery

You already know that in HTML there is no search option in the dropdown element.

When you press any single key in the dropdown then it takes you to the option but does not allow you to search whole or particular string.

Searching is required on the list when there is a long list of items that are available.

It is time-consuming to find the option by scrolling the list.

In this tutorial, I show how you create a dropdown with a search box using the select2 plugin and read the selected option.

Make a Dropdown with Search Box using jQuery

Read more

How to delete file with jQuery AJAX

Using Client-side scripts like – jQuery and JavaScript it is not possible to delete any files. Need to use Server-side scripting for doing it.

In PHP, you can simply use the unlink() function this removes a file from your server if it exists.

Sometimes you have the requirement to delete a resource file without reloading the page.

This cannot totally be done with PHP you need to use jQuery or JavaScript with it by which send AJAX request to your server for removing a file and according to the response make changes on your Client-side.

For demonstration purpose, I create some <img> elements with Delete Button. When the Button gets clicked then remove the file using jQuery AJAX and replace the <img> source with the default image.

How to delete file with jQuery AJAX

Read more

How to Concatenate Multiple columns in MySQL

In this tutorial, I show how you can concatenate multiple columns in MySQL.

You can simply do this programmatically by separately select fields from MySQL Table and store their values in the single variable after concat their values.

But you can make the above process a little simpler by concatenating the values while selecting rows from DataBase Table.

Let’s take a simple example –

You have two columns – firstname, lastname within your DataBase Table you want to show both the columns values in a single string form. In this case, you can use MySQL functions to combine the values of the columns.

There are two functions for doing this –

  • CONCAT
  • CONCAT_WS

Both functions work similarly but have little difference.

How to Concatenate Multiple columns in MySQL

Read more

MySQL – Convert Unix Timestamp to Date Time

The Unix Timestamp, while efficient for data storage, lacks human readability and appears as a set of integer numbers to users. To make it more user-friendly, it requires conversion into a readable format before displaying it to end-users.

If you don’t perform this conversion directly while selecting rows from the Database Table, you’ll need to handle it programmatically. For example, in PHP, you can utilize the date() function for conversion like so:

$timestamp = 1690768832;
echo "date time : ".date('d-M-Y H:i:s a',$timestamp);

The above code gives the following output:

date time : 31-Jul-2023 02:00:32 am

In this tutorial, we will explore how to convert Unix Timestamp values into a more readable Date Time format when selecting data from a MySQL Database Table. Let’s dive in and make the process of converting Unix Timestamps more accessible and comprehensible.

MySQL - Convert Unix Timestamp to Date Time

Read more