Create advanced (combined) search

thread: 5 messages  |  last: a year ago  |  started: monday, january 30, 2012, 3:51 am pst

#1  |  dorito (Antwer, Belgium) Belgium
Monday, January 30, 2012, 3:51 AM PST

Hello Guys,

I'm trying to create an advanced search function for my users. The idea is simple, the can combine 2 listboxes an 2 textboxes (with dates) to filter a list of reports.

This is how it goes:

“I'd like to see all reports from <<lstUsers>> for the <<lstPatients>> that were entered between <<dttStartDate>> and <<enddate>>”

Creating the above is no problem. However how do I create the logic behind it.

this is my first try:
   $QQfilterClause = array();
                   if($this->lstFilterPatients->SelectedValue !== null){
                   if($this->lstFilterUsers->SelectedValue !== null){
                    * Start and endtime
                    $arrDateParts = explode('.',$this->dttFilterStartTime->Text);
                    $dttFilterStartDate = new QDateTime(QDateTime::Now);
                    $dttFilterStartDate->setDate($arrDateParts[2], $arrDateParts[1], $arrDateParts[0]);

                    $arrDateParts = explode('.',$this->dttFilterEndTime->Text);
                    $dttFilterEndDate = new QDateTime(QDateTime::Now);
                    $dttFilterEndDate->setDate($arrDateParts[2], $arrDateParts[1], $arrDateParts[0]);
                    array_push($QQfilterClause,QQ::GreaterOrEqual(QQN::Vpc()->VpcDate, $dttFilterStartDate));
                    array_push($QQfilterClause,QQ::LessOrEqual(QQN::Vpc()->VpcDate, $dttFilterEndDate));

                    $arrVpcs = Vpc::QueryArray($QQfilterClause);
                    $this->dtgVpcs->DataSource =$arrVpcs;

The QueryArry doesn't accept the array with the conditions.

Any help is most appreciated

#2  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, January 30, 2012, 6:59 AM PST

Use QQ::And() instead of pushing the conditions on top of each other.

So something like:

    $objCondition = QQ::All();

    if ($txtFilter1->Text) {
        $objCondition = QQ::AndCondition($objCondition, QQ::Equal(QQN::Foo()->Bar, $txtFilter1->Text);

    if ($txtFilter2->Text) {
        $objCondition = QQ::AndCondition($objCondition, QQ::Equal(QQN::Foo()->Bar, $txtFilter2->Text);

    if ($txtFilter3->Text) {
        $objCondition = QQ::AndCondition($objCondition, QQ::Equal(QQN::Foo()->Bar, $txtFilter3->Text);

    // Etc.

hope that helps...

#3  |  dorito (Antwer, Belgium) Belgium
Monday, January 30, 2012, 3:35 PM PST

Hi MIke,

Sure helps. But what if the user has entered both field 1 and 2? Or 2 and 3? Or 1 and 3...

You get the point.

The current solution only supports one filter.

Best regards

#4  |  dorito (Antwer, Belgium) Belgium
Monday, January 30, 2012, 3:38 PM PST

NEver mind Mike.

Stupid me :-)

#5  |  dorito (Antwer, Belgium) Belgium
Sunday, September 24, 2017, 12:49 PM PDT

For old times sakes:

Just needed this again and after searching the forum was helped by this post after 5 years again!

So sad Qcodo/Qcubed never really gained enough traction.

Thanks again Mike for everything.

Copyright © 2005 - 2019, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.