How to pretty JSON fromat using JavaScript/jQuery?

Pretty JSON example

Pretty JSON example

So many time we required ti print the JSON in pretty format because it is easy to read and understood. As we know JSON (JavaScript object notation)  is a lightweight data-interchange format. It is easy for humans to read and write.
In this article you will learn how to print JSON in pretty format at browser.



Here is the CSS code create a new css file named as stylesheet.css.
stylesheet.css

I have used CSS for highlighting the key, value and strings.
Here is the JavaScript and HTML code to print the JSON in pretty format.



index.html

Here in JavaScript I have cerated a function to make the JSON in pretty format. Here we have a products JSON and we are printing products JSON in pretty format. ...  Read More

Share This:


Simple Shopping Cart in PHP & MySQL | PHP code for Shopping Cart

Shopping Cart Example PHP

Shopping Cart Example PHP

There are many e-commerce application and we are still building e-commerce application but all of them has common functionality and the functionality is shopping cart.

We are here to learn, How to build a simple shopping cart in PHP and MySQL? In this article I'll be creating a very simple cart system where you will be able to add the products into the cart and can remove the products from the cart. You also will be able to empty cart or remove all products from the cart.


Here are the MySQL queries:

I'll be using session to add or remove the products from the cart. First of all I'm fetching products from MySQL and listing all the products on the web page.
Create a new PHP file like:
index.php

Here is the simple products listing. I also have add to cart button here and a text field to enter the quantity. I also have used connection file here which creates a connection with MySQL using PHP...  Read More

Share This:


Live Email Availability Checking using PHP, jQuery and Ajax

Often in registration form we need a a feature to check the live availability of user. Obviously it is worth that after submitting all the details to tell the user that user already registered. It's better approach to tell the user while filling the form.

email-id-available
In this article, we will see a live check availability of email id by using AJAX, jQuery, and MySQL.
You will require to enter the email id and you will be able to check weather the email id already exist or not while typing the email id.



Here is the HTML and jQuery part. ...  Read More

Share This:


How to delete duplicate records from MySQL table | MySQL query to delete duplicate records

Many of the interviews I was asked a common MySQL question and the questions was, Write a MySQL query to delete the duplicated records from MySQL table.
Here in this small article I'll be explaining MySQL query to get duplicate records and to delete the duplicate records.

For example you have a users table and inside the users table we have duplicate email id of user so the first question how to get the duplicate records ?
Here is the MySQL query to get the duplicate records:

It will return duplicate emails along with the count of duplicate emails.



Now we wanted to delete the duplicate records. Here are some scenarios, either you wanted to keep the highest record or you wanted to keep the lowest record. ...  Read More

Share This:


Real time commenting System with Node and MongoDB | Real time commenting on post using Node.js and Socket.io

Nodejs comment system example

Nodejs comment system example

So many applications required real time programming and believe me Node.js and Socket.io is the best combination or that. So many applications required real time commenting system. Today in this article you are going to learn how you can comment in real time in Node.Js by using Socket.io.

In my previous Node.js tutorial I explained video streaming in Node.js with the help of socket.io.
Today also I'm going to use socket.io for creating the real time comment system in node.js.

I'll create a simple commenting system. There will be a listing of posts. I'll be fetching the posts from MongoDB. You also will be able to view detail of every post. On detail page of posts you could comment in real time. I'm also saving your comments in MongoDB along with real time commenting. So whenever you'll see the post detail you could see the comments. ...  Read More

Share This:


Video stream with Node.js & Socket.io | Stream data in Node.js using Socket.io

video-streaming-node-js-example

Video streaming example in Node.js || Socket.io

Let me tell you one thing that real time video streaming in Node.js is super simple. When the question comes in our mind to stream data we think Ohhh.. this is very big task and you overhead yourself.

In this article I'll explain you that you can stream your data with few lines of code by using sockets.

I'll be using socket library to stream the data in real time. I also will be using express module for just to manage my routes and to defining my static directories.

I'm assuming that you have installed Node.js and NPM at your system. ...  Read More

Share This:


Dynamic database connection in Laravel 5.5 | Multiple database connection in Laravel 5.5 | MySQL & Redis database connection in Laravel | Change database or schema dynamically in a connection

So many time If we are working on a big application we need to keep out data in multiple databases. This is very easy to manage multiple database connections in Laravel. You also can create your database connection at run time.

Inside your database configuration file you can define multiple database connections. Like in Laravel 'config/database.php' we can define our multiple database connections.

We also can set our database or schema dynamically within a database connection.

I will show you 3 MySQL and 1 Redis database connection as multiple database connection and I also will connect them dynamically. ...  Read More

Share This:


How many columns we can update in single MySQL query and What is maximum length of column name, table name and database name?

  • We can update maximum 64 columns in a single MySQL query.
  • A column name of MySQL table can be upto 64 characters.
  • A MySQL table name can be of 64 characters.
  • A MySQL database name can be of maximum 64 characters.

Share This:


Server side DataTable in PHP,MySQL and Ajax | DataTable in PHP and MySQL | DataTables Example - Server-side Processing with PHP | DataTables example - Server-side processing | Add column in DataTable in PHP

Server side DataTable Example

Server side DataTable Example

We often display data in tables. We do pagination, searching and sorting manually on those tables. DataTables is the beautiful concept for doing all these things you can say your food is ready to eat. You just need to use some peace of code and you can display data in tables with beautiful features like Pagination, Searching and Sorting.

We will display data in chunks so that this will be easy for MySQL to serve the data. It'll also increase your performance You can change your pagination limit as well for example if you wanted to display 25 records on every page you can do that very easily.


 ...  Read More

Share This:


Laravel RESTful API Tutorial | Laravel RESTful API Example | Login, Register, Logout, and CRUD API in Laravel | Laravel RESTful API Development

A Web API is like a web service which works entirely with HTTP. A RESTful API must follow the REST (REpresentational State Transfer) practices, allowing to orientate the design to the resources, provide standard responses based on the different HTTP status codes.

Methods

HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to create or update, the basic patterns are listed as follows.

HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP PATCH: Update an existing resource or collection of resources with specified parameters like in all users data if you wanted to update the email id only you can use PATCH.
HTTP DELETE: Delete a resource or collection of resources. ...  Read More

Share This: