observe field in symfony

While using observe_field , pls take a note that never use ‘with’ => “‘regCode=’ + $(‘region’).value” instead of that  use :’with’ => “‘regCode=’+value” as the former method is incompatible with lower versions of firefox

echo(observe_field(‘region’, array(‘update’ => ‘updateCountry’, ‘url’ => ‘default/updateCountry?className=DrpDwnBox194FL’,’script’=>true, ‘with’ => “‘regCode=’ + $(‘region’).value”, ‘loading’  => “Element.show(‘loadingId’);Element.hide(‘updateCountry’)”, ‘complete’ => “Element.hide(‘loadingId’);Element.show(‘updateCountry’)”)));

echo(observe_field(‘region’, array(‘update’ => ‘updateCountry’, ‘url’ => ‘default/updateCountry?className=DrpDwnBox194FL’,’script’=>true, ‘with’ => “‘regCode=’+value”, ‘loading’  => “Element.show(‘loadingId’);Element.hide(‘updateCountry’)”, ‘complete’ => “Element.hide(‘loadingId’);Element.show(‘updateCountry’)”)));

writing a custom query in symfony

//it is javascrit file need to include at run time in ajax
$this->response = $this->getResponse();
//end  javascript of file need to include at run time in ajax

$selSearch = $this->getRequestParameter(‘selSearch’);
$txtSearch = $this->getRequestParameter(‘txtSearch’);
$extrVar =’&mainpg=1′;
if($selSearch) $extrVar .=’&selSearch=’.$selSearch;
if($txtSearch) $extrVar .=’&txtSearch=’.$txtSearch;

$userId = $this->getUser()->getAttribute(‘userId’);
$this->currentUserId = $userId;

$objUser = UserPeer::retrieveByPK($userId);
$countryCode = $objUser->getUsrCountry();

//$endodedURL = $this->getRequestParameter(‘endodedURL’);

//$this->endodedURL = $endodedURL;

//here replacing the following special character – , _ , + , * , / , #
$txtSearchwithSpace = preg_replace(“[%]”,’\%’,addslashes(preg_replace(“@[-_+*/#]@”,” “,$txtSearch)));
$txtSearchwithoutSpace = preg_replace(“[%]”,’\%’,addslashes(preg_replace(“@[-_+*/#]@”,””,$txtSearch)));
$txtSearch = addslashes($txtSearch);
$txtSearch = preg_replace(“[%]”,’\%’,preg_replace(“[_]”,’\_’,$txtSearch));

$objQtzReagent = new qtzReagent();

$sqlQuery = “”;
$sqlQuery = “SELECT SQL_CALC_FOUND_ROWS “.ReagentsPeer::REA_NAME.” AS rea_name_old, “.ReagentsPeer::REA_VENDORID.” AS rea_vendorid, “.ReagentsPeer::REA_CATALOGUEID.” AS rea_catalogueid, “.ReagentsPeer::REA_CATALOGUEID.” AS rea_catalogueid_R, IF( “.ReagentsPeer::REA_USRID.” = ‘”.$this->currentUserId.”‘,’yes’,’no’) AS reagent_own, “.ReagentsPeer::REA_VENDORID.” AS rea_vendorid_R, “.ReagentsPeer::REA_ID .” AS rea_id_old, “.ReagentsPeer::REA_VENDORID.” AS rea_vendorid, “.ReagentsPeer::REA_USRID.” AS rea_usrid, “.ReagentsPeer::REA_TYPEID.” AS rea_typeid, “.ReagentsPeer::REA_NOOFCOMMENTS.” AS rea_no_comments, “.ReagentsPeer::REA_AVGRATING.” AS rea_avgrating, count(*) AS reaCount, (SELECT COUNT( “.ReagentRatingsPeer::RER_ID.” ) FROM “.ReagentRatingsPeer::TABLE_NAME.” WHERE “.ReagentRatingsPeer::RER_VENDORID.” = rea_vendorid_R AND “.ReagentRatingsPeer::RER_CATALOGUEID.” = rea_catalogueid_R ) AS ratingCount, ( SELECT “.ReagentsPeer::REA_NAME.” FROM “.ReagentsPeer::TABLE_NAME.” WHERE “.ReagentsPeer::REA_VENDORID.” = rea_vendorid_R AND “.ReagentsPeer::REA_CATALOGUEID.” = rea_catalogueid_R AND “.ReagentsPeer::REA_PRIVATE.” = ‘0’ GROUP BY “.ReagentsPeer::REA_NAME.” ORDER BY COUNT(*) DESC, “.ReagentsPeer::REA_NAME.” ASC, reagent_own DESC LIMIT 1 ) AS rea_name, ( SELECT “.ReagentsPeer::REA_ID.” FROM “.ReagentsPeer::TABLE_NAME.” WHERE “.ReagentsPeer::REA_VENDORID.” = rea_vendorid_R AND “.ReagentsPeer::REA_CATALOGUEID.” = rea_catalogueid_R AND “.ReagentsPeer::REA_PRIVATE.” = ‘0’ GROUP BY “.ReagentsPeer::REA_NAME.” ORDER BY COUNT(*) DESC, “.ReagentsPeer::REA_NAME.” ASC, reagent_own DESC LIMIT 1 ) AS rea_id FROM “.ReagentsPeer::TABLE_NAME.” LEFT JOIN “.UserPeer::TABLE_NAME.”  ON (“.ReagentsPeer::REA_USRID.” = “.UserPeer::USR_ID.”)  WHERE 1 “;
$sqlQuery .= ” AND “.ReagentsPeer::REA_ENABLE_SELFRATINGCOMMENT.” = ‘1’ AND “.UserPeer::USR_COUNTRY.” = ‘”.$countryCode.”‘  AND “.ReagentsPeer::REA_PRIVATE.”=’0′ AND “.ReagentsPeer::REA_PRODUCTTYPE.”=’nonvendor’ AND “.ReagentsPeer::REA_AVGRATING.”<>” AND (“.ReagentsPeer::REA_NAME.” LIKE ‘%”.$txtSearch.”%’ OR “.ReagentsPeer::REA_NAME.” LIKE ‘%”.$txtSearchwithSpace.”%’ OR “.ReagentsPeer::REA_NAME.” LIKE ‘%”.$txtSearchwithoutSpace.”%’)  GROUP BY “.ReagentsPeer::REA_VENDORID.”, “.ReagentsPeer::REA_CATALOGUEID.’ ORDER BY ‘.ReagentsPeer::REA_AVGRATING.” DESC, ratingCount DESC ” ;

$con = sfContext::getInstance()->getDatabaseConnection(‘propel’);
$records = sfConfig::get(‘app_paging_perpagelist’);

$curPage = $this->getRequestParameter(‘pageNv’, 1);
$limit = $records;
//$limit = 2;

$startLimit = ($curPage – 1) * $limit;

$sqlQuery .= ” LIMIT “. $startLimit.”, “.$limit;

//echo $sqlQuery;

$objRslt = $con->executeQuery($sqlQuery);

$this->objRslt = $objRslt;

$strCountQuery = “SELECT FOUND_ROWS() as totRec”;
$rsCnt = $con->executeQuery($strCountQuery);
$this->totRec = $rsCnt->get(‘totRec’);

$pager = myGeneric::getCustomPagerArray($curPage, $limit, $this->totRec);

$this->pager = $pager;
$this->objRslt = $objRslt;
$this->currentPage = $curPage;

if ($curPage && $this->endodedURL) {
$tmpURL = base64_decode($this->endodedURL);
$tmpURL = unserialize($tmpURL);
$tmpURL[‘pageV’]=$this->getRequestParameter(‘pageV’, 1);
$this->endodedURL = base64_encode(serialize($tmpURL));
if($this->endodedURL) $extrVar .=’&endodedURL=’.$this->endodedURL;

$this->objQtzReagent = $objQtzReagent;

$this->extrVar = $extrVar;

Creating graphs and charts with PHP

To create graphs, charts or pie chats in php is really easy with jpgraphs library available for php. Here’s how you can use this library.

first of all download the jpgraphs from the links given as follows: for php4 , for php5. or you can directly go the jpgraph site.

after downloading the zip file, just unzip the file and copy paste the folder to the webroot or the www folder to access it through your localhost or webserver.

open the folder and go to the examples directory, where you can see lots of examples listed for dynamic graphs and chart generation.

select the example that suits best to your requirment and find the code for the example there.

below given are some image examples of how a graph or chart created with jpgraph library looks like:

How to connect MSSQL with php

Please follow the steps given below to connect MSSQL with php:

1. Settings related to your php.ini file:

a) search the variable mssql.secure_connection in your php.ini file and put it to on mode if its off
b) remove comment from the dll extention php_mssql.dll (i.e. remove the ; from the front of the extention )

2. Settings related to the dll files.

download a file name ntwdblib.dll from the internet. you can download it from here or can search on internet for that. copy the downloaded dll to the apache/bin directory and for IIS copy it to the php extention directory (if path not known can be found in php.ini for variable extension_dir)

also you need to have your php_mssql.dll in your php extension directory. if its not present please download it and copy it to the default php extension directory.

3. restart all your services (i.e. php and apache or iis) and you can use the script given below to connect to your SQL Server.

//mssql.secure_connection = On
// Need to upload ntwdblib.dll from net

$myServer = “DVLP066\SQLEXPRESS”; // host/instance_name
$myUser = “sa”; // username
$myPass = “sadvlp066”; // paasword
$myDB = “myfraiche”; // database name

// connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die(“Couldn’t connect to SQL Server on $myServer”);

// select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die(“Couldn’t open database $myDB”);

echo “You are connected to the ” . $myDB . ” database on the ” . $myServer . “.”;

$query = “SELECT top 10 * FROM tbl_customers”; // your database query
$result = mssql_query($query);
while($row = mssql_fetch_assoc($result))
// close the connection

Creating virtual host on apache, php

You can create a virtual host on your local system or your sever. i.e. you can have http://trial/ instead of http://localhost/trial/ where trial is the name of the directory that contains the website.

Here are the steps for creating virtual host on your sever:

1) open the host file and edit it as follows:

the host file is found at C:\WINDOWS\system32\drivers\etc\hosts for windows

open the file and add the following code to the bottom of the file on a new line       trial

2) Now open the httpd.conf file under the apache/bin/conf/ directory

and add the following code :  # Virtual hosts
Include conf/extra/httpd-vhosts.conf

or if already present then please uncomment the following line
: Include conf/extra/httpd-vhosts.conf

i.e. remove the # from the front of the line

3) Open apache/bin/conf/extra/httpd-vhosts.conf file

if not present create directory extra under

and create a file httpd-vhosts.conf file

and add this code to the file:

# Virtual Hosts
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/&gt;
# for further details before you try to setup virtual hosts.
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.
<Directory D:/wamp/www/vhosts>
Order Deny,Allow
Allow from all
# Use name-based virtual hosting.
NameVirtualHost *:80

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.localhost
#    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost”
#    ServerName dummy-host.localhost
#    ServerAlias http://www.dummy-host.localhost
#    ErrorLog “logs/dummy-host.localhost-error.log”
#    CustomLog “logs/dummy-host.localhost-access.log” common

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.localhost
#    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost”
#    ServerName dummy-host2.localhost
#    ErrorLog “logs/dummy-host2.localhost-error.log”
#    CustomLog “logs/dummy-host2.localhost-access.log” common

<VirtualHost *:80>
DocumentRoot D:/wamp/www
ServerName localhost
<VirtualHost *:80>
DocumentRoot D:/wamp/www/vhosts/trial
ServerName trial

if the file is present then please add the following lines at the bottom of the file

<VirtualHost *:80>
DocumentRoot D:/wamp/www
ServerName localhost
<VirtualHost *:80>
DocumentRoot D:/wamp/www/vhosts/trial
ServerName trial

4) restart your apache services and just type http://trial/ into the address bar of your browser and it will work

If you face any problem with this please feel free to contact me. I’ll try to resolve your problem as soon as possible.


Sachin (samsami2um@gmail.com)

Autoload class files – PHP 5

In PHP 5 you can auto load all the classes you want with a function available in PHP 5. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.

The condition to use this approach is that you should have one class per file; also the file name and class name should be same.

  1. This reduces your code and efforts to include long list of class files that you need to access classes. So here are the steps to auto load the class files in PHP5:
  2. Put all the classes files in a specific directory or folder. (i.e. classes, includes etc.)
  3. function __autoload($class_name) {
    $class_path = ‘classes/’; // relative or physical path of the folder or directory containing classes
    $class_extn = ‘.php’; // class file extention .php or in some cases .class.php
    $path = $class_path.$class_name.$class_extn;
    require_once $path;

  4. Include this function in place of long list of include statements of class files.
  5. $mobj=new myclasschild();

    $assigned = $mobj;

  6. Now just initialize your class object as you usually do when including class files.
  7. Thats all

Hope this helps you,

Sachin (samsami2u@gmail.com)

Automatic destructor in PHP4

class demoClass{

function demoClass(){
register_shutdown_function(array(&$this, ‘__destruct’));

$argcv = func_get_args();
call_user_func_array(array(&$this, ‘__construct’), $argcv);

function __construct(){
//your code for constructor goes here

function __destruct(){
//your code for destructor goes here


//Hope this method help you out with your problems.

//Hope this helps you,

//Sachin (samsami2u@gmail.com)