Skip to main content

Posts

Showing posts from March, 2014

how to get the first 500 record from table in php mysql mysql

we are geting first 500 record form table using php and mysql mysql_connect("hostname", "username","") mysql_select_db("databasename"); $sql = "SELECT * FROM table ORDER BY id DESC LIMIT 50"; $result = mysql_query($sql);   while ($query = mysql_fetch_assoc($result))     {     echo "$query[fieldname1] $query[fieldname2] <br/>"; }

find visitor location php

<?php function geoCheckIP($ip)   {   //check, if the provided ip is valid   if(!filter_var($ip, FILTER_VALIDATE_IP))   {   throw new InvalidArgumentException("IP is not valid");   }   //contact ip-server   $response=@file_get_contents('http://www.netip.de/search?query='.$ip);   if (empty($response))   {   throw new InvalidArgumentException("Error contacting Geo-IP-Server");   }   //Array containing all regex-patterns necessary to extract ip-geoinfo from page   $patterns=array();   $patterns["domain"] = '#Domain: (.*?)&nbsp;#i';   $patterns["country"] = '#Country: (.*?)&nbsp;#i';   $patterns["state"] = '#State/Region: (.*?)<br#i';   $patterns["town"] = '#City: (.*?)<br#i';   //Array where results will be stored   $ipInfo=array();   // &nbsp;   //check response from ipserver for above patterns   foreach ($patterns as $key

how to get google map coordinates by address in php

<?php function getCoordinates($address){ $address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address"; $response = file_get_contents($url); $json = json_decode($response,TRUE); //generate array object from the response from the web return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']); } echo getCoordinates('Hyderabad, Andhra Pradesh, India'); ?>

wordpress author related taxonomy posts

wordpress author related taxonomy posts <?php global $post; $author_id=$post->post_author; $args = array(                                     'post_type' => 'deals',                                     'author'=> $author_id                                 );                                 $the_query = new WP_Query( $args );                                 if ( $the_query->have_posts() ) :                                     while ( $the_query->have_posts() ) : $the_query->the_post();                                         the_title();                                     endwhile;                                     //wp_reset_query();                                 endif; ?>

how to get difference between two dates in php

how to get difference between two dates in php <?php $date1 = new DateTime("2006-09-07"); $date2 = new DateTime("2014-03-19"); $interval = $date1->diff($date2); echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; ?> Output : difference 7 years, 6 months, 12 days