Skip to main content

Posts

Showing posts from October, 2011

Excel export php

The below code can export data from database into excel sheet using php: <?php $filename ='excelreport.xls'; mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("test"); $res = mysql_query("select id, country from countries"); $contents = ''; while($row = mysql_fetch_assoc($res)) { $contents .= $row['id']."\t".$row['country']."\n";        } header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename='.$filename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); echo $contents; ?>

Joomla facts

Joomla Facts i observed and experienced: 1. To find whether the user is logged in or not in your joomla site.... try this code: <?php $user =& JFactory::getUser(); echo '<span style="background-color:#333; color:#ff0000;">ID: '.$user->id.'</span>'; ?> If the user is not logged in, the ID would be generally 0.  2. Generally to load an article, the following params in the url are sufficient: index.php?option=com_content&view=article&id=153 But i saw that some modules like search and translate are not displaying in the article page, until we also add the Itemid parameter to the article url.  ex: &Itemid=157 So the complete article url would be: index.php?option=com_content&id=153&view=article&Itemid=157 3. Below is a sample code to invoke 'login' module in joomla. Try adding this code in your template file. <?php jimport('joomla.application.module.helper'); $module = JMod

Browser tips and tricks, my tests

Note that, by default, Firefox and IE align the page elements differently. For ex, Firefox aligns elements to the left, and IE to center. Hence you may need to write in your page, like: align="left" to get the left display properly in IE. If you want to control the display of elements in IE6 and other browsers, you can use !important property. (People still using IE6 are not better than early men). A way to control the display of elements in IE6 and other browsers: .main-nav { margin-top: 10px; *margin-top: 20px; } // IE6 takes margin-top: 20px, other browsers take margin-top: 10px; Check that there are no unclosed comments in the file, in either css or javascript code, like for example, the html comments are opened, but not closed later. Better to write the style tags before the script tags in a file, as browsers like chrome may not work properly. Its better to include the css (and probably js ?) files in the header file. Because the css is global for the enti

Using firebug in browsers other than IE

Method1: Add this script in your page: <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> Method2: Copy this javascript in your url and hit enter: javascript:var%20firebug=document.createElement('script');firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js');document.body.appendChild(firebug);(function(){if(window.firebug.version){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);

Send Mail php

<?php $to = 'dskanth.99@gmail.com'; $subject = 'Your Verification Code'; $body = 'Hello world'; $headers = "From: shashi <dskanth.99@yahoo.com>". "\r\n"; $headers .= "MIME-Version: 1.0" . "\r\n"; // HTML $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // HTML if(mail("$to","$subject","$body","$headers")) echo 'Mail sent'; else echo 'Error'; @mail("dskanth.99@gmail.com","Another email","Hello world","$headers"); // no error displayed ?> Note: Better to give double quotes for the parameters in mail function.

Javascript popup window examples

 Example - 1 <script type="text/javascript"> function open_chat_window() {     testwindow = window.open("http://www.google.co.in", "Google popup Window", "menubar=1,resizable=1,width=682,height=570");     testwindow.moveTo(150, 150); } </script> <body> <a href="#" onclick="open_chat_window();">Open Google in popup</a> </body> Example - 2 <script type="text/javascript"> var width = 800;  var height = 600;  var left = parseInt((screen.availWidth / 2) - (width / 2));  var top = parseInt((screen.availHeight / 2) - (height / 2));  var windowFeatures = "width=" + width + ",height=" + height    + ",menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,left="    + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;       child1 = window.open("popup_window.php", "subWind&qu