Monthly Archives: September 2013

google map with calculate between more than two places in php

<?php
$travel_location = ‘1st main Road&Peenya Industrial Area’;

$bootloca = explode(‘&’,$travel_location);
$origins = str_replace(‘ ‘, ‘+’, $_REQUEST[‘city’]);
$destinations = ”;
foreach($bootloca as $book):
$destinations = $destinations.str_replace(‘ ‘, ‘+’, $book).’|’;

endforeach;

$json=file_get_contents(“http://maps.googleapis.com/maps/api/distancematrix/json?origins=&#8221;.$origins.”&destinations=”.$destinations.”&mode=driving&sensor=false”);

$json=json_decode($json,true);
//print ‘<pre>’;
//print_r($json);   // for check array value
//print ‘</pre>’;
$total_distance = 0;
foreach($json[“rows”][0][“elements”] as $dist):

$total_distance += ceil($dist[“distance”][“text”]);

endforeach;

print $total_distance;
?>

Advertisements

Logout link for Joomla 1.5, 2.5

Joomla 1.5 Logout Link

<?php
$returnURL = base64_encode(JURI::root() . “”);
$user =& JFactory::getUser();
echo ‘Hi,’.$user->username;
?>

<a href=”index.php?option=com_user&task=logout&return=<?php echo $returnURL; ?>”>
<input  type=”button” name=”Submit” value=”Logout”></a>

Joomla 2.5 Logout Link

<a href=”index.php?option=com_users&task=user.logout&<?php echo JUtility::getToken(); ?>=1″>
<input  type=”button” name=”Submit” value=”Logout”>
</a>

 

Edit profile link for joomla 2.5

<a href=”<?php echo JRoute::_(‘index.php?option=com_users&view=profile&layout=edit’)?>” title=”My Profile”>Edit Profile</a>

 

how to access Joomla 2.5!: Classes for Accessing Database for mysql

For select Query:

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('field1,fieldn');
$query->from('#__tablename');
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results){
    foreach($results as $result) 
    {
        //$result->field1
        //$result->fieldn;
    }
}
 
For insert Query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert('#__tablename');
$query->set("field1='value1', fieldn='valuen'");
$db->setQuery($query);
$db->query();
To get the last insert id, use:
$db->insertid();


For udate Query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update('#__tablename');
$query->set("field1='value1', fieldn='valuen'");
$query->where("fieldx='valuex'");
$db->setQuery($query);
$db->query();
 
For simple query: 
$db = JFactory::getDbo();
$query = "<YOUR QUERY>";
$db->setQuery($query);
$db->query();

For fetch multiple row:

Your Query goes here
$items = $db->loadObjectList();


For fetch Single row:

Your Query goes here
$book_item = $db->loadObject();