Skip to main content

Posts

Showing posts with the label Programming Aid

PHP function to get dates between two dates in an array

Function in PHP to get dates between 2 dates in an array Here is a simple function in PHP which accepts FromDate and ToDate as input dates. The dates should be in dd/mm/yyyy format. Function takes the input dates and returns an inclusive array of the dates between the from and to dates.

MySQL query to list Items and its categories.There are tables for Items, Categories and Item_category relation. One item may fall in different categories. In the result there should be no repeation of records and Categories should be comma separated.

There is an ITEM table , CATEGORY table and an ITEM_CATEGORY relation table. Items may fall in multiple categories "Item" table has item id and item name.  "cat" table has Category Id and Category Name. There is a third table  to store the item category relation. "Item_cat" table  contains Itm_Id (item id) and cat_Id (category id). Here the question is how to generate a result like this ItmName  ##    Category Item1 ##    Cat1,Cat3 Item2 ##    Cat2 Item3 ##    Cat1,Cat4 Item3 ##    Cat1 Sample MySQL query to list Items and its categories. In this example there are tables for Items, Categories and Item_category relation. One item may fall in different categories. In the result there should be no repeat of records and the categories should be comma separated.

MySQL CONCAT() function returns NULL when one of the argument field value is NULL - Fix

MySQL String Concatenate Functions - MySQL CONCAT() function returns NULL when one of the argument field value is NULL In MySQL for concatenating two or more stings or Field values we use CONCAT() .It returns the string that results from concatenating the arguments. So even if all the argument fields except one have valid data it will return NULL

PHP function to return the domain or subdomain from a given url

PHP code to return the domain name from a given url string Here is a simple function which uses regular expression to find the domain name from a given url string. Input to the function is the URL string.

MySQL query to retrive only one record for a repeating column or rows of data

MySQL query to retrive only one record for a repeating column or duplicate rows of data Suppose there is a table tbl_BOOKS which stores records of various books. some books comes under different categories. so there may be multiple records with same BookReferenceNumber. But when user searches for a particular reference number, the search result should display only one record eventhough there are multiple entries for same BookReferenceNumber. Let us illustrate this with a sample table given below:

itunes rss feed podcast sample

Sample iTunes RSS Feed Podcast iTunes iTunes is a proprietary digital media player application, used for playing and organizing digital music and video files. The application is also an interface to manage the contents on Apple's iPod and iPhone lines, as well as the iPad. iTunes can connect to the iTunes Store via the Internet to purchase and download music, music videos, television shows...etc Users can subscribe to any podcast by entering its RSS feed URL, but also by browsing the podcast directory within iTunes Music Store. RSS Feed Information The iTunes RSS feed is based on RSS 2.0 specifications, with a few notable additions. The additional tags, specific to iTunes are: <itunes:category> <itunes:explicit> <itunes:subtitle> <itunes:summary> <itunes:author> <itunes:keywords> <itunes:duration> <itunes:owner> <itunes:name> <itunes:email> <itunes:image> <itunes:block> <copyright...

AddDate - php function to add days months or years to a date

addDate() : PHP FUNCTION TO ADD DAYS MONTHS OR YEARS TO A DATE AND RETURNS FUTURE DATE. This function accepts the date in d/m/Y format It can add days ,months and years to the supplied date It will return future date in user supplied format. It generates the time stamp of future date and formats it and returns. If the supplied date is not in d/m/Y format then function will return nothing. function addDate ( $inputDate,$days2Add=0,$months2Add=0, $years2Add=0,$outputDateFormat="Y-m-d" ) { //assuming supplied date in d/m/Y change it to m/d/Y $futuredate=""; $arrDate=@explode("/",$inputDate); $reformedDate=$arrDate[1]."/".$arrDate[0]."/".$arrDate[2]; if( checkdate($arrDate[1],$arrDate[0],$arrDate[2]) ){ //if date is valid then return future date else return null $id = strtotime($reformedDate); //preserve time $futuredate= date($outputDateFormat, mktime(date('h',$id), date('i',$id), date('s'...

Date functions

addDate() : PHP FUNCTION TO ADD DATE This function accepts the date in d/m/Y format It can add days ,months and years to the supplied date It will return future date in user supplied format. It generates the time stamp of future date and formats it and returns. If the supplied date is not in d/m/Y format then function will return nothing. function addDate ( $inputDate,$days2Add=0,$months2Add=0, $years2Add=0,$outputDateFormat="Y-m-d" ) { //assuming supplied date in d/m/Y change it to m/d/Y $futuredate=""; $arrDate=@explode("/",$inputDate); $reformedDate=$arrDate[1]."/".$arrDate[0]."/".$arrDate[2]; if( checkdate($arrDate[1],$arrDate[0],$arrDate[2]) ){ //if date is valid then return future date else return null $id = strtotime($reformedDate); //preserve time $futuredate= date($outputDateFormat, mktime(date('h',$id), date('i',$id), date('s',$id), date('m',$id)+$months2Add, date('d',$id)+$days2Add, dat...

PDF generation in PHP

There are several ways to generate PDF files using PHP OPTION #1 One of the most adorable features of PHP 4 is the PDFLib extension, which allows you to dynamically construct PDF documents in Adobe Portable Document Format. For this you must have the PDFLib library installed on your system. If you're working on Linux, you can download a copy from http://www.pdflib.com/ and compile it for your box. If you're running Windows,a pre-built PDF library is bundled with your distribution, and all you need to do is activate it by uncommenting the appropriate lines in your PHP configuration file. In addition to this a PDF viewer application like Adobe PDf reader must be installed in your machiine to view the PDF file. More on PHPLib Extension OPTION #2 Another option is to use the PDF genertion Class files available as opensources. Example: 1. FPDF 2. TCPDF 3. MPDF FPDF CLASS FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib lib...


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog