<!– something random just like junk – yard –>

Symfony Criteria for table alias with join of same table

Posted in LAMP, learning, opensource, programming by ganu on March 31, 2009

Symfony Criteria for table alias and join a quick example.

Yesterday got a good situation, A kind of join with same table and with table alias.
I need to use the first query with symfony criteria.

I got this, hope this will be usefull to you too.

SELECT u1.USR_FNAME AS a, u1.USR_LNAME AS b, u2.USR_FNAME AS c, u2.USR_LNAME AS d, u3.USR_FNAME AS e, u3.USR_LNAME AS f
FROM tbl_test
LEFT JOIN tbl_users u1 ON ( tbl_test.TEST_USER1_ID = u1.USR_ID )
LEFT JOIN tbl_users u2 ON ( tbl_test.TEST_USER2_ID = u2.USR_ID )
LEFT JOIN tbl_users u3 ON ( tbl_test.TEST_USER3_ID = u3.USR_ID )
ORDER BY tbl_test.TST_ID ASC
LIMIT 10
$c = new Criteria();
   	$c->clearSelectColumns();
   	$c->addAlias('u1','tbl_users');
   	$c->addAlias('u2','tbl_users');
    $c->addAlias('u3','tbl_users');
   	$c->addSelectColumn(TblProjectPeer::TST_NAME);
   	$c->addAsColumn('a','u1.USR_FNAME');
   	$c->addAsColumn('b','u1.USR_LNAME');
    $c->addAsColumn('c','u2.USR_FNAME');
    $c->addAsColumn('d','u2.USR_LNAME');
  	$c->addAsColumn('e','u3.USR_FNAME');
   	$c->addAsColumn('f','u3.USR_LNAME');
   	$c->addJoin(TblTestPeer::TEST_USER1_ID,'u1.USR_ID',Criteria::LEFT_JOIN);
   	$c->addJoin(TblTestPeer::TEST_USER2_ID,'u2.USR_ID',Criteria::LEFT_JOIN);
  	$c->addJoin(TblTestPeer::TEST_USER3_ID,'u3.USR_ID',Criteria::LEFT_JOIN);

Or take another example

SELECT a.id FROM article a RIGHT JOIN article b ON a.article_id = b.id ORDER BY a.name DESC, b.date DESC
$c=new Criteria();
$c->addAlias('a', 'article');
$c->addAlias('b', 'article');
$c->addSelectColumn('b.id');
$c->addSelectColumn('a.article_id');
$c->addDescendingOrderByColumn('a.name');
$c->addDescendingOrderByColumn('b.date');
$c->addJoin('a.arcticle_id','b.id','RIGHT JOIN');
$rs = ArticlePeer::doSelectRS($c);

Happy Programming. :cool:

prototype and jquery conflict-clash-compatibility issue

Posted in observation, programming, tips by ganu on March 15, 2009

Yesterday we got major clash/compatibility issue or conflict :shock: with jQuery and Prototype.
We were using javascript slider and menu with jQuery and some popup window with prototype window.

Searched a lot :evil: , Then finally came up with 2 solution.

  1. Every one says change in jQuery, prototype doesnt have any thing like this.
  2. we got this link solving the conflict/clash/compatibility withing jQuery and Prototype
var $j = jQuery.noConflict();

     // Use jQuery via $j(...)
     $j(document).ready(function(){
       $j("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();

So where ever you are getting “$” change this to “$j” or any variable what ever you like.

Really, jQuery is built is such at superb way, so this proves that this is fully dynamic.

What a solution sir ji, wah!! 3 cheers to jQuery guys.

Lession learnt : first see the requirment, dont just use any js library that suites your requirment. See the dependency then go ahead. :cool:

PHP & MySQL quick search bookmarklets

Posted in LAMP, learning, opensource, tips by ganu on January 25, 2009

If you want to quick search to MySQL, here is the fast quick bookmarklet

javascript:q=document.getSelection();
if(!q)void(q=prompt('MySQL%20Keyword:',''));
if(q)location.href='http://search.mysql.com/search?q='+escape(q)

And the same goes for PHP too same like above…

javascript:term=document.getSelection();
if(!term)void(term=prompt('PHP%20Keyword:',''));
if(term)location.href='http://in2.php.net/'+escape(term)

Happy Programming. :D

quick symfony tips.

Posted in LAMP, learning by ganu on June 23, 2008

I am learning symfony. Just got some good tips to share with you.
Symfony rocks. :)

I will update this regularly.

1> How to write OR condition query in symfony.
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(TablePeer::TBL_ID);
$cton1 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton2 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton1->addOr($cton2);
$c->add($cton1);

2> How to get query where first date greater then and less then last date.
$date1 = date('Y-m-d 00:00:00');
$date2 = date('Y-m-d 23:59:59');
$cton1 = $gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date1, Criteria::GREATER_EQUAL);
$cton1->addAnd($gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date2, Criteria::LESS_EQUAL));
$gUser->add($cton1);

3> how to run the update query in symfony.

“update table TableName set TableField1=’1′ where TableField2=$some_value.”

$update = new TableName();
$update->setNew(false);
$update->setTableField1(1);
$update->setTableField2($imageId); // this is primary key of the table. include this line.
$update->save();
?>

technorati tags:
, , , , (more…)

Tagged with: , , , ,

velue of programming code – hindi version

Posted in General, Timepass, fun, hindi by ganu on December 14, 2007

एक चुटकी कोड की क़ीमत तुम क्या जानो बाबू? 
ईश्वर का आशीर्वाद होता है एक चुटकी कोड.

डेवेलपर के सर का ताज होता है एक चुटकी कोड, 
हर टेसटर का को चाहिए एक चुटकी कोड.

हर पी.एम. का डेड-लाइन होता है एक चुटकी कोड,
हर सी.ई.ओ. का भविष्य होता है एक चुटकी कोड.

हर बेंच रीसोर्स का ख्वाब होता है एक चुटकी कोड,
हर क्लाइंट का एक-एक डॉलेर/पौंड होता है एक चुटकी कोड.

अरे तुम क्या जानो क्या होता है एक चुटकी कोड ??
हर सॉफ्टवेर - इंजिनियर की आन - बान और शान होता है एक चुटकी कोड.

got 4 line poem in english, other 6 lines are mine. :)

Technorati Tags: , , , , , ,, , ,

Find last day of the month in PHP

Posted in LAMP, learning by ganu on February 28, 2007

Yday I was working with dates and got the situation to get the last day of the month so got this piece of code.

date(’Y-m-d’,strtotime(’-1 second’,strtotime(’+1 month’,strtotime(date(’m').’/01/’.date(’Y').’ 00:00:00′))));

And this piece of code will gv you the last day of the your corrent month. 

tags: , , ,