Web Toolbar by Wibiya

Access Request variables from smarty templates

January 25, 2011 – 5:13 pm

In smarty templates you can access Request variables available in PHP scripts using the reserved template variable {$smarty}.  Request variables include $_GET, $_POST, $_SERVER, $_ENV, $_COOKIE and $_SESSION.

Read the rest of this entry »

Tips to speed up mysql queries

January 24, 2011 – 12:09 pm

1. Instead of VARCHAR, BLOB or TEXT, Use CHAR type when possible. if values of a column have constant length: MD5-hash (32 symbols), ICAO or IATA airport code (4 and 3 symbols), BIC bank code (3 symbols), etc. Data in CHAR type columns can be found faster rather than in variable length data types columns.

2. Just because of you have too many columns, don’t split a table . In accessing a row, the biggest performance hit is the disk seek needed to find the first byte of the row.

Read the rest of this entry »

How to load data into table from a text file ?

January 24, 2011 – 9:44 am

Here we are assuming that we have a  table with given structure:


CREATE TABLE teasttable (
prkey int(11) NOT NULL auto_increment,
names varchar(20),
score int,
timeEnter timestamp(14),
PRIMARY KEY  (prkey)
);

Read the rest of this entry »

Smarty – Passing ‘title’ variable to header template

January 23, 2011 – 6:46 pm

Generally when majority of your templates use the same headers and footers, it is obviously a good choice to split those out into their own templates and include them. But what if the header needs to have a different title, depending on what page you are coming from? For this you can pass the title to the header when it is included.

Read the rest of this entry »

Smarty – Handle blank variables

January 23, 2011 – 6:40 pm

Sometimes instead of printing an empty variable you may need to print a default value. For example printing a sign “*” instead of printing nothing so that the page should appear in understandable form. Yes! you can use rather most of the people use {if} statement for this but there is a shorthand way also with smarty and that is using default variable modifier.

Read the rest of this entry »

Alternate css styles in smarty using {cycle} tag

January 22, 2011 – 1:47 pm

Displaying rows or tables of information in alternate background colors is a nice way to improve readability. You may have used alternate css style in template using  {if} tag but there is a smarty tag {cycle} which you can use to set the alternating CSS styles.

Here is a sample code that sets “oddstyle” or “evenstyle” css class to rows of a table in alternates.

Read the rest of this entry »

How to access template variables from PHP script ?

January 22, 2011 – 1:13 pm

Using Smarty method get_template_vars(), you can access the smarty template variables  in PHP scripts. However, these template variables are only available after or  during the execution of template. The other way to use those template variables can be achieved by embedding PHP code directly into the smarty template using {php}  tags or by including a php file using the {include_php} tag.

Consider the code written in a index.tpl template:


{assign var='title' value='This is an example'}

Read the rest of this entry »