المشاركات

عرض المشاركات من مارس, ٢٠١٨

How to Add Images to Dropdown List using jQuery

صورة
Hi! In this post, let's see how to add images to dropdown list using jquery . I had a form with a drop-down element for the list of countries and wanted to insert the corresponding country flag before each country name. But HTML does not support the addition of elements to select box. Then I found some CSS hack but this method is not compatible with all browsers. Finally, I decided to go with java script and found a fairly neat solution. Actually, it is a jquery plugin called 'select2'. It includes the autocomplete feature to dropdown list , but also allows you to add icons to those select options. Below, I'll show you how to use the select2 add-on to insert country flags before the country names in a drop-down list. jQuery - Adding Images to the Dropdown List: STEP-1) First load the 'jQuery' and 'Select2' libraries on the Web page. You need to add both 'css' and 'js' files of the plugin. <link href="https://cdnjs.cloudflar...

Dynamic Treeview Menu using PHP, MySQL and AJAX Example

صورة
How to Create Dynamic Treeview Menu using PHP, MySQL and AJAX? Most modern websites use tree view to display the dynamic sidebar menu for easy navigation. In case you don't know, a Treeview is a hierarchical representation of elements in a tree-like structure. You can go for jquery solution in this context, but I would recommend 'Bootstrap Treeview' plug-in if you use the bootstrap framework to build your websites. The plug-in uses JSON dataset to create a hierarchical tree structure. I have already discussed the creation of static treeview menu using bootstrap treeview . But you can also generate a dynamic tree where you pull off the data elements stored in the database. In this tutorial I'm going to show you about creating dynamic treeview using php, mysql, ajax and bootstrap. How to Create Dymanic Treeview in PHP & MySQL? For the demo, I'm going to load all the required libraries via CDN. So there's no need to download them to your web server. Here...

Generate PDF from View using DomPDF in CodeIgniter 3

صورة
Hi, in this post let's see how to generate pdf from view using dompdf in codeigniter 3 . When it comes to generating reports, the pdf format is the most popular in use. In addition, many websites offer downloadable documents, forms and files in pdf format by converting from html to pdf. There are several add-ons and libraries to aid with the process, such as DOMPDF, MPDF, FPDF, TCPDF, Html2Pdf etc. In this case, I will use the DomPDF library to generate PDF documents in code igniter. DomPDF renders the html layout to a PDF file and supports the loading of external style sheets and inline css styles when creating pdf. How to Generate PDF from CodeIgniter View? Here we are going to see how to generate pdf document from a codeigniter view file. Basically dompdf reads the html content, create pdf from html and writes it to the output stream. The following are the steps to implement PDF generation in code igniter. STEP-1) First download dompdf library, then extract and move th...

How to Send AJAX Request at Regular Interval

صورة
At times, you may want to update part of a web page repeatedly. Let's say, for example, that you have a website flashing live news or a cricket score update. Here you have to refresh that specific content on a regular basis and ajax is the best way to do it. You are left with two options when you want to fire ajax request at specific time interval - one is setInterval() and the other is setTimeout() function. Both JavaScript functions are good for doing periodic tasks, but one is much better than the other. In this tutorial we will see what is the best approach and how. Fire Continuous AJAX Request using setInterval(): The setInterval() is the common method used for repeated tasks. It executes a function at specified interval in milliseconds. Repeated calls can only be stopped using the clearInterval() method or by closing the window. setInterval(function, milliseconds); Consider the following example. This java script will fire ajax call every 5 seconds to the server a...

Convert HTML to PDF in PHP using DomPDF Library

صورة
Hi! In today's post we will see how to convert html to pdf in php using dompdf library. DomPDF is basically a php library that offers a simple way to convert html content to pdf so that you can generate pdf files on fly with php. Frameworks like Laravel offers separate packages to create pdf files, but there is not so much luck when you work on core php. Hence we need external tools for the task and DomPDF is a good fit for it. The library creates downloadable pdf file from the html webpage. It supports CSS2.1 and CSS3 and renders the html layout including the styles. It also handles @import, @media and @screen queries and can load external stylesheets while generating the pdf. 1. Convert HTML to PDF - Basic Usage: Download the dompdf archive from here and extract the contents to your root folder. After that, create a sample php file, 'index.php' and include the autoloader file to load the required dompdf libraries and helper functions into your PHP project. The fol...

AJAX Pagination in CodeIgniter Tutorial

صورة
Hi! In this post, we will see how to make ajax pagination in codeigniter using codeigniter pagination library . The Pagination class offers feature rich functions to paginate the query results in view. Although the usage of pagination library is well-documented, paginating the results with jquery ajax is somewhat a mystery. The solutions available around the web are too complicated for beginners. Hence I decided to write a tutorial on the topic that is easy enough for anyone to implement codeigniter pagination with ajax. For this example, we'll need two libraries which are jQuery and Bootstrap . The jQuery.js is for making ajax call and bootstrap is for designing the user interface. CodeIgniter AJAX Pagination Example: To create ajax pagination, I'm going to use the default pagination library of the code igniter framework. Simply follow the below steps to implement the same. STEP-1) Create Database First create the required database, table and the records to use in our ...

PHP - Send Email via SMTP Server using PHPMailer

صورة
Hi! In this post, let's see how to use PHPMailer to send email from PHP . PHPMailer is an amazing php library to send emails quickly. We all know the generic PHP's mail() function helps you send emails. But on the downside, it requires local mail server to send them. And also the setup and configuration is not that easy. But that's not the case with PHPMailer. The library supports SMTP protocol and allows easy authentication over SSL and TSL. It allows you to display error messages in more than 40 languages in case there is an error when sending emails. PHPMailer uses the real valid email address to send mails. Hence you have to setup one if you don't have it. Here, let's see how to use Gmail SMTP to send email via PHPMailer. Sending Email via Gmail SMTP using PHPMailer: SMTP is basically a mail protocol that sends a request to the mail server and after verification sends it to the mail server of the recipient. To send an email via smtp, you need the authenti...

10 Best Laptops for Writers & Writing 2018

صورة
Are you looking for the best laptop for writers? Then here's our review for Top 10 Best Laptops for Writers and Writing 2018 . No matter if you are a professional writer, seasonal or a novice there's a laptop for everyone's budget here. The laptops we have recommended are for people who use them mainly for writing purpose and made sure they got spacious backlit keyboard, eye friendly display, no overheating issues and light weight but sturdy chassis. Best Writers Laptop Configuration: Are there any special laptops made for writing? Well! No. But a laptop specifically used for writing must have certain features that would make a writer's life easier. Here we go. Keyboard: Backlit Keyboard (to write in low-light conditions) with spacious palm rest. Storage: At least 128GB SSD (SSD is faster and produce less heat. A must for professional writers who writes all day long) RAM: 6 to 8GB RAM Processor: Good Quad core processor like Intel i3 Portable: Light...

How to Find the Second Highest Salary with MySQL Query

صورة
Hi! Today's post is about a popular interview question, which is the sql query to find the second highest salary . Most freshers would have faced this question in their interviews. There is not one single solution for this. You can approach in different ways to get the second maximum salary from the database. Here I'm going to show you some of the best possible ways you can write the sql query to fetch the salary that is second highest. I've tried these queries on MySQL but it also works with other relational databases such as MSSQL Server, Oracle etc., that uses SQL. Finding the Second Highest Salary: Consider the following table. It consists of a set of employee records and we are going to use in our queries to get salary that is second largest. Table Name: Employees ID Name Designation Salary 1 Colleen Hurst Regional Director 205500 2 Garrett Winters Ac...