Symfony Criteria for table alias with join of same table
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.
prototype and jquery conflict-clash-compatibility issue
Yesterday we got major clash/compatibility issue or conflict
with jQuery and Prototype.
We were using javascript slider and menu with jQuery and some popup window with prototype window.
Searched a lot
, Then finally came up with 2 solution.
- Every one says change in jQuery, prototype doesnt have any thing like this.
- 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.
![]()
PHP & MySQL quick search bookmarklets
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.
quick symfony tips.
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:
PHP, code, sf, symfony, programming (more…)
velue of programming code – hindi version
एक चुटकी कोड की क़ीमत तुम क्या जानो बाबू?
ईश्वर का आशीर्वाद होता है एक चुटकी कोड.
डेवेलपर के सर का ताज होता है एक चुटकी कोड,
हर टेसटर का को चाहिए एक चुटकी कोड.
हर पी.एम. का डेड-लाइन होता है एक चुटकी कोड,
हर सी.ई.ओ. का भविष्य होता है एक चुटकी कोड.
हर बेंच रीसोर्स का ख्वाब होता है एक चुटकी कोड,
हर क्लाइंट का एक-एक डॉलेर/पौंड होता है एक चुटकी कोड.
अरे तुम क्या जानो क्या होता है एक चुटकी कोड ??
हर सॉफ्टवेर - इंजिनियर की आन - बान और शान होता है एक चुटकी कोड.
got 4 line poem in english, other 6 lines are mine.
Technorati Tags: hindi, software, engineer, programming, program, bangalore,PJ, poem, funny,
Find last day of the month in PHP
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: PHP, code, month, programming





