المشاركات

عرض المشاركات من ديسمبر, ٢٠١٧

Submit Form using jQuery AJAX and PHP without Page Refresh

صورة
Hi! In this tutorial we will see how to submit form using jquery ajax and php without page refresh . Web Development enhanced with AJAX increases speed and performance thereby improving the overall user experience. It allows you to update part of a web page without refreshing it completely. Basically, when you submit an html form, the entire page will be refreshed. But by using ajax technique, you can submit the form to the web server without having to reload the page. Instead, the form data will be submitted to the server in the background and can be processed in any way you want. How to Submit Form using jQuery AJAX and PHP? The jQuery library provides ajax() method which allows you to submit form without refreshing page . It will send an HTTP request to the web server (here is the php script), which is then processed by the server and sends an http response. Let's see how to do it. Step 1) Create a Basic HTML Form First let's create a simple html form containin

jQuery Datatables with PHP, MySQL and AJAX Example

صورة
Hi! In this tutorial let's look at the server-side processing of jquery datatables using php, mysql and ajax . In case you don't know, Datatables is an amazing jquery plugin that converts the simple html table into a feature-rich data grid with additional functions like instant search, pagination, multi-column sorting etc. The table works with multiple data sources like DOM, AJAX etc., and supports both client and server side processing. We have already seen about datatables with json data and here we will see about server side processing. For the server script, we are going to use PHP and MySQL as a data source. jQuery Datatables Server-side Processing with PHP and MySQL: Let's see how to fetch records from the server-side using ajax request and list it in the data tables. To use in this example, we need a dummy database. So let's create it first. Step 1) Create MySQL Database The following sql will create a mysql database, a table and some sample records i

How to Filter Array by Value in PHP

صورة
Today let's see how to filter array by value in php . When working on a large data set, it would be useful to filter array values based on conditions. For this, you must iterate through the array, check each element against some condition and decide to keep it or discard it. It is a task that takes a lot of time to say. Luckily you don't have to fuss over this. With PHP's native array_filter() function, you can filter the array using callback where you can specify the condition to filter each element of the array. The function returns the array containing elements that are successfully passed through the callback. Using Array_Filter in PHP: The function array_filter() filters elements of an array using a callback function. array_filter(array, callback, flag) The function takes up three parameters of which the first one is mandatory and the rest others are optional. array - The array to be filtered callback - The callback function to use as a conditional fi

Connect to Multiple Databases with PHP MySQLi and PDO

صورة
Hi! In this tutorial, we'll see how to connect to multiple databases using PHP's MySQLi and PDO (PHP Data Object) library. At times you may want to work with multiple mysql databases in the same context. Therefore, you need to connect to two or more databases in the same mysql instance and fetch data from them simultaneously. The old 'MySQL' extension has been deprecated since PHP5.5, so I would recommend you to use 'MySQLi' or even better 'PDO' , which provides an additional layer of security and supports multiple databases such as MySQL, MSSQL Server, PostgreSQL, Oracle and much more. The databases can be on the same server as php script or on different server. No matter what, connecting php to remote mysql server is similar to the one on the same server, except that you must provide permission to access the remote database. Connecting Multiple Databases with PHP MySQLi: Establishing connection to multiple databases using mysqli api is eas

Get Address from Latitude and Longitude using PHP and Google Maps API

صورة
Hi! Today let's see how to get address from latitude and longitude using PHP and Google Maps Geocoding API . In general, the process of converting geometric coordinates such as latitude and longitude into address is called reverse geocoding . And the geocoding is just the opposite, converting address into latitude and longitude which we have seen in our previous tutorial. Google Maps provides a separate Geocoding API for the purpose and let's see how to use it with php. To obtain physical addresses from the API, you have to send http request along with latitude and longitude values. Getting Address from Latitude and Longitude using Google Maps: To access Google Maps Geocoding API , you need an http interface through which you can send and receive an http request/response from the api. Here is the sample request you should send to the web service. http://maps.google.com/maps/api/geocode/json?latlng=40.6781784,-73.9441579 The 'latlng' parameter must be used t

Get Latitude and Longitude from Address using PHP and Google Maps API

صورة
Hi! In this tutorial, let's see how to get latitude and longitude from address using google maps geocoding api and php . Geocoding is the process of converting physical addresses into geographical coordinates such as latitude and longitude so you can use them to create markers in Google Map. It is also better to provide latitude and longitude when using Google Map API so that you can point to accurate position on the map. To obtain the geocode, we must send an http request to the Google Map Geocoding API along with the formatted address. How to Get Latitude and Longitude from Address? The Google Maps Geocoding API is a web service used to obtain geocoding and reverse geocoding of the addresses. And you have to access the api through the HTTP interface. Here is the sample request you have to send to Geocoding API to get latitude and longitude coordinates. The API provides a response in both json and xml format. Since json is cross platform compatible, let us inform the

How to Update Data in Database using ID in CodeIgniter

صورة
How to update data in database using id in codeigniter? . Using codeigniter update query will let you perform update operation on database. In the previous post, I explained you about how to insert data into database using codeigniter and bootstrap . This tutorial will demonstrates you about updating database records in codeigniter. CodeIgniter DB Update is going to be very easy as we have made required ground coding in CodeIgniter Database Insert tutorial. The update model, controller, and the view files will share some of the same features like insert along with fewer coding of its own. Update Data in Database using ID in CodeIgniter If you are a regular reader of Koding Made Simple , then you would have known, in most of my tutorials I use Twitter Bootstrap CSS Framework to design the front end. In this codeigniter database update tutorial too, I'm going to combine bootstrap with codeigniter to design the update form. Setting up MySQL Database For DB, I'm going to

How to Get User IP Address in CodeIgniter

صورة
Hi, this quick post discusses about getting user ip address in php codeigniter framework. Say you have an application built on code igniter mvc and you want to collect visitor's ip address. The easiest solution is to use the codeigniter's input class. CodeIgniter input class serves two important purposes. 1. It ensures security by pre-processing the global input data and 2. It does provide helper functions to fetch the input data and pre-process it. Unlike other codeigniter libraries, we don't have to manually initialize this input class as it is done automatically by the system. Get IP Address of the User in CodeIgniter The input class provides two built-in functions namely ip_address() and valid_ip() to process the ip address. To get the ip address of the current user use it like this, $ip = $this->input->ip_address(); This returns the current user's ip address. It returns 0.0.0.0 if the ip is not valid. Validate IP Address With the help of the

Autocomplete Textbox using HTML5 Datalist, PHP and MySQL Example

صورة
Autosuggest Textbox is a cool technique to enhance user experience in websites. It's a google like search box which pops up suggestions while you type and lets you choose the word(s) without typing it completely. Usually this feature requires third party tools like jquery plug-ins to implement but thanks to HTML5, you can do it with plain html and php alone. In this tutorial, I'm going to show you, how easy it is to integrate HTML5 auto complete textbox from database using PHP and MySQL. Autocomplete Textbox from Database using HTML5 and PHP The HTML5 DATALIST element adds up autocomplete feature to ordinary textboxes and it takes up several options similar to SELECT element. To implement auto suggest from database, we should fetch the data and populate it to the datalist options. Finally integrate this datalist to a textbox element and we are done. Let's see how to do it in php and mysql. Step-1: Connect to MySQL Database in PHP First establish the connectio

How to Install and Setup PHP CodeIgniter Framework in XAMPP Localhost

صورة
Though I have written several php codeigniter tutorials in the past, this post is solely aimed at absolute beginners who want to set foot in this php mvc framework. The lure of codeigniter is its pretty small learning curve and the flexibility to accommodate small to large web applications. MVC frameworks demands structured workflow and it's necessary to configure properly for them to work. This codeigniter tutorial will walk you through step by step on how to install and setup the codeigniter framework in xampp stack. Install CodeIgniter in XAMPP First download codeigniter latest version and extract its contents to the "htdocs" folder of XAMPP. Rename the folder to some application name such as "ci_demo". CodeIgniter Folder Structure CodeIgniter follows a certain folder (directory) structure and consists of three folders namely "system" , "application" and "user_guide" . PHP CodeIgniter Folder Structure System: The

Search Multidimensional Array for Key Value in PHP

Arrays are generally used to store and manipulate data with ease and known to be one of the core building blocks of PHP Programming . When properly used, arrays are a great tool to process large amount of data efficiently - be it from database server or from a third-party source. But they can become nasty once you start working with multidimensional array which by itself is an array of arrays i.e., every element of the array turns out as an array. Below example is a good representation of a multi-dimensional array. PHP Multi Dimensional Array $color = Array ( ('r') => Array ( ('red') => 255, ('green') => 0, ('blue') => 0 ), ('g') => Array ( ('red') => 0, ('green') => 255, ('blue') => 0 ), ('b') => Array ( ('red') => 0, ('green') => 0, ('blue') => 255 ) );

How to Embed PDF File in HTML Page

صورة
Hi, today we’ll see how to embed pdf file in a html page directly. Some websites tend to show pdf files directly on their site’s webpages instead of giving a download link for the files. Thanks to HTML5, you can also do the same with simple html code without using any third party solutions. The method we are going to see is the quick and easy solution which gives you some control over how the pdf file is shown to the user. Also it works on all modern web browsers that support HTML5. How to Embed PDF File in HTML Page HTML5 provides <embed> element which acts as a container for external application like image, videos, mp3 files or other multimedia objects. Using this tag makes the browser to automatically include controls for the multimedia objects (in case the browser supports the particular media type). We are going to use this <embed> tag to show the pdf files in the web page without using complex third party scripts. Open the html page in which you want to e

How to Convert Multidimensional Array to XML File in PHP

صورة
Hi, today we’ll see how to convert multidimensional array to xml file in php. XML, the EXtensible Markup Language is a good old data-exchange format and lost its popularity to JSON. But the sad truth is XML still exists and used to store and exchange data on the WEB. If you are one among the developers who has to deal with XML, then this tutorial is aimed at you. Converting an associative array or a complex multi-dimensional array no matter what, the php script I have given here will easily convert those arrays to xml file. Converting PHP Multi-Dimensional Array to XML File Here’s the breakdown of the steps we are going to implement for php array to xml conversion. Step-1: Create a function array2XML() to convert array to xml: This function will continuously iterates through the given multi-dimensional array and add each (key, value) pairs as a separate xml node with the help of php’s SIMPLEXML class. Step-2: Next define the php associative or multi-dimensional array to