Skip to main content

Posts

Showing posts from October, 2010

USD to INR conversion

<?php function currency($from_Currency,$to_Currency,$amount) { $amount = urlencode($amount); $from_Currency = urlencode($from_Currency); $to_Currency = urlencode($to_Currency); $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency"; $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); $data = explode('"', $rawdata); $data = explode(' ', $data['3']); $var = $data['0']; return round($var,2); } echo currency("USD","INR",1.00); ?> Note: It needs the curl extension to work properly.

Add 1 year javascript

<html> <head> <script> function addYear(fName,daysToAdd) { var fDate =new Date(document.dates.Today.value); fDate.setDate(fDate.getDate()+daysToAdd); var MM = fDate.getMonth()+1; var DD = fDate.getDate(); var YY = fDate.getFullYear(); if(MM<10) MM="0"+MM; if(DD<10) DD="0"+DD; document.dates.NextYear.value = YY+"-"+MM+"-"+DD; } </script> </head> <body onLoad="javascript:addYear('NextYear',365)"> <form name="dates"> <input type=text name="Today" value="2010-10-17" size="10"> <input type=text name="NextYear" size="10"> </form> </body> </html>

using random in php query-mysql

<?php $res = mysql_query('SELECT COUNT(*) AS count FROM mytable'); $row = mysql_fetch_assoc($res); $rows_count = $row['count']; // to get the count of rows in your table, then: $r = mysql_query('SELECT * FROM mytable LIMIT '.mt_rand(1, $rows_count).', 1'); ?>

Assign smarty variables to javascript

This is an example of assigning a smarty array to a javascript variable: {literal}<script>var aa = '';</script>{/literal} {foreach from=$media_path_array name=input_loop key=k item=v} {literal} <script> aa += '{/literal}{$v}{literal}##'; // alert(aa); </script> {/literal} {$v}## {/foreach} {literal} <script> function assign_vals() { // alert(aa); // alert(bb); if(aa == '' || bb == '') { alert("Please upload an image first to cancel the upload"); } document.cancel_upload_form.media_path_array.value = aa; alert(document.cancel_upload_form.media_path_array.value); document.cancel_upload_form.submit(); } {if !empty($media_path_array)} <form name="cancel_upload_form" action='{$action}' method='POST'> <div id='cancel_upload' style='display: block;'> <a href='javascript:void(0)' onclick="javascript:assign_vals()">{lang_print id=90000115}</a&g