Makitweb Posts

In jQuery, there are various methods like – switchClass(), toggleClass(), addClass() and removeClass() by using them you can easily add or removes classes in the elements.

For using switchClass() method you need to include jQuery UI library within your page but you can simply use toggleClass(), addClass() and removeClass() without any dependency other than jQuery.

In this tutorial, I discuss about addClass() and removeClass() method.

.addClass() and .removeClass() methods in jQuery

Read More .addClass() and .removeClass() methods in jQuery

Jquery

The data is not displayed in any particular order when you simply fetch it from MySQL table. For displaying data in some meaningful way ORDER BY clause is used.

This sorts your result on the basis of column name specified in the clause within the SELECT query.

It allows us to –

  • Specify ordering in single or multiple columns
  • Define sort results in ASC or DESC format.

How to use order by with multiple columns in MySQL

Read More How to use Order by with Multiple columns in MySQL

DataBase

The checkbox element in HTML allows us to select multiple items from the group of values.

When you use it in your form and try to read all checked values as any other elements like –  text box, text area, radio button etc.

echo $_POST['lang'];  // Checkbox element

you will get the last checked value.

You need to send the checkboxes value in the form of an Array when the form gets submitted then you can loop over $_POST values.

Get checked Checkboxes value with PHP

Read More Get checked Checkboxes value with PHP

PHP

The break statement is used to ends the execution of the current loop or switch case statement in PHP.

But when working with nested loops and wants to exit out from all or some of the outer loops. For this, you need to pass numeric value following with break statement.

In this tutorial, I show how to out from two inner loops and n number of nested loop.

How to Break the nested loop in PHP

Read More How to Break the nested loop in PHP

PHP

There is the various approach of selecting the last insert id from MySQL table.

  • Select a single row from the table in descending order and store the id.
  • Select Maximum value.
  • The following query gives you next AUTO_INCREMENT value from selected table which you can use to get the last id.
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'user'

If your currently AUTO_INCREMENT column last value is 8 and when you execute the above query on the Table this will return 9.

In PHP there is an inbuilt method which simply returns the last insert id according to the previous insert query.

Get last insert id from MySQL Table with PHP

Read More Get Last insert id from MySQL Table with PHP

DataBase PHP

In PHP, it is possible to upload multiple files using single input file element. You just need to customize your single file upload PHP code and enable your file element to select multiple files.

In this tutorial, I show you how to implement multiple files upload with PHP.

Multiple files upload at once with PHP

Read More Multiple files upload at once with PHP

PHP

When you have the large collection of images files on a directory and you wants to convert it into the photo gallery.

Solution 1

Add image file manually to your page one by one which you want to show. The problem with this solution is it is time-consuming and you have to check all image links if any update in future.

Solution 2

Store image names in the Database table and use it to get images.

Solution 3

Read all files from target directory and generate photo gallery.

The second and third solution are better but in this post, I will show you how to implement the third solution with PHP.

How to make photo gallery from image directory with PHP

Read More How to make Photo Gallery from image Directory with PHP

How To PHP

The CSS media queries are very helpful when making the responsive website. They automatically execute the changes when the window size is in its range.

There is another way to detect Browser window size and execute changes is with jQuery that gives you window width and height.

You can use those values to complete your task.

Capture Browser window resize with jQuery

Read More Capture Browser Window resize with jQuery

Jquery

Jquery

In HTML it is not possible to add an element in the dropdown list. You need to customize it.

For example –

If you try to add a search box in an <option> or add a country flag image following with country name. When you run it you don’t see any changes in the dropdown.

You can do both operations with select2 jQuery plugin.

Insert image in dropdown lists with jQuery

Read More Insert Image in Dropdown lists with jQuery

Jquery