and Where greater than less than

When setting up an ActiveDataProvider in search function, you may need to pass a value and have it evaluated and less then (<) or greater than (>). I did not find this info straight forward. But, it is not hard.

Here is an example:

  1. $query->andWhere('table_name.date_created >= :date_val',[':date_val' => $_GET['date_val']);

This utilizes parameter binding, so it is safe to pass the $_GET parameter into it.

You will not need to use ‘table_name’ if you are not using a join clause.

More likely, you will use something like $this->date_val or $this->getAttribute(‘date_val’) rather than $_GET[‘date_val’].

Published by

Joel Bowers

Web developer since 1999. PHP, YII2, Laravel, Javascript, HTML, CSS, jQuery, Perl, Wordpress, MySQL.

Leave a Reply

Your email address will not be published. Required fields are marked *