Forums

double search field on ccv6

teldrive 20 May, 2020
Hi I have this php code working on CCv5 but I am trying to translate it to ccv6 in where conditions in a read field function
<?php
if(!empty($_POST['filtername1']) && !empty($_POST['filtertext1'])){
$filter1 =$_POST['filtername1'];
$text1=$_POST['filtertext1'];
if(!empty($_POST['filtername2']) && !empty($_POST['filtertext2'])){
$filter2 =$_POST['filtername2'];
$text2=$_POST['filtertext2'];
return array(":{$filter1} LIKE" => "%{$text1}%" , ":{$filter2} LIKE" => "%{$text2}%" );
}else{
return array(":{$filter1} LIKE"=>"%{$text1}%");
}?>
this simple code works on ccv6
<?php
return [["venta.num","1997"]];
?>
and also works to assign a variable to field value
<?php
return [["venta.num","{data:valor1}"]];
?>
but I couldn't make variable the field to search that comes from a dropdown, is it possible in ccv6?, for example this simple test
<?php
$this->data['filtro1_sel']="num";
$this->data['valorl']="1997";
return [[":{data:filtro1_sel}","{data:valor1}"]];
?>
gives me this error 1054Unknown column 'venta.:{data:filtro1_sel}' in 'where clause'
Max_admin 21 May, 2020
Hi Teldrive,

Did you try the new v7 ? the "Search listing" behavior in the Text fields can be added to multiple fields and it would apply the where conditions to the list automatically!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 21 May, 2020
Hi Max
I see only version 6 in chronoengine web , anyway is there any possibility to assign variable to field condition? I have a lot of work done in v6
GreyHead 22 May, 2020
Hi Teldrive,

The beta version of CFv7 is available from the Blog menu above.

Bob
teldrive 22 May, 2020
hi bob I will try, but for a production solution is very risky go ahead with beta. I understand there is not work around for this topic in ccv6
thanks anyway
healyhatman 23 May, 2020
In your conditions, just put in all the fields and choose "skip" or "ignore" if it's null.

Or if you absolutely must have a dropdown, then you'll just have to build the query yourself.
teldrive 23 May, 2020
Hi healyhatman, thanks by the clue, sometimes I forget the ccv6 flexibility, but some i need some adittional help
$this->data['filtro1_sel']="num";
$this->data['valor1']="1997";
//---------------------------starts query
$db = JFactory::getDbo();
// Create a new query object.
$query1 = $db->getQuery(true);
$query1->select($db->quoteName(array('id','ano','bruto','neto','iva','irpf','fechaini','tipoventa')));
$query1->from($db->quoteName('#__cf_venta'));
$filter1=$this->data['filtro1_sel'];
$text1=$this->data['valor1'];
//$query1->where($db->quote($filter1)." LIKE ".$db->quote($text1));
$query1->where($db->quoteName('num')." LIKE ".$db->quote($text1));
$query1->order($db->quoteName('fechaini').'DESC');
$db->setQuery($query1);
return $db->loadAssocList();
this works fine, but when try with the variable field "$db->quote($filter1)", fails
$query1->where($db->quote($filter1)." LIKE  ".$db->quote($text1));
is something missing?, by the way how can I request model "venta" into to query1 I tried with
$query1->from($db->quoteName('#__cf_venta','venta'));
but it doesn't work
Max_admin 24 May, 2020
I think the code at the first post will be something like this:
$where = [];
if(1){$where = ["field1", "value1", "="];}// you may replace "=" by LIKE
return $where;
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 24 May, 2020
Hi Max, thanks by this other method, I tried and works but it necessary the double bracket not sure why
<?php
$this->data['filtro1_sel']="num";
$this->data['valor1']="1997";
if(1){$where = ["num", "1997", "="];}
return [$where];
?>
I was wrong before because is not possible to pass variable to field or value , I am not sure if I am missing something
if(1){$where = ["num", "{data:valor1}", "="];}
if(1){$where = ["{data:filtro1_sel}", "{data:valor1}", "="];}
by the way let me ask if you can help how to get a "model" based array using query when I return "$db->loadAssocList()" I think this could be a workarund;
Max_admin 24 May, 2020
yes, it's necessary to use double brackets, because this is a group of where settings!

you do not have to use if(1), that was just an example!

The loadAssocList is a Joomla function, the model array is a gcore feature, you need to use the GCore code for that!

and I do not think it's a good idea to get the field name by the {data:} call like you do now {data:filtro1_sel}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 24 May, 2020
Hi Max, awaiting any clue about how can I generate a model array with Gcore ;-) or how can generate "where conditions" with variable field-value as in ccv5 (if possible) Anyway opening my mind and exploring all posibilities I decided to try CFv7
I see Cfv7 has very high potential if possible to merge cc and cf in one package, I miss some demos ,
trying to implement a basic ccv6 viewlist I am working on i think this integration can be with module "table list" , but how do I define source data for this table?
fighting until find a solution🧐
Max_admin 24 May, 2020
"where conditions" with variable field ? you mean like in your first post ? just use my code and instead of "if(1)" use your own condition!

There is a FAQ on how to work with GCore database models class, but you do not need that since you can just use the "Read Data"

You can find attached a basic articles listing in v7, I hope it helps!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 24 May, 2020
Hi Max, we got it, this code works with one search filed where condition with parameters field and value😀
(i insert pictures because blog process brackets )


just a little adittional help , how can I combine two where conditions( if possible), I tried two options without sucess
return [$where]." AND ".[$where];
and



Max_admin 24 May, 2020
your syntax is wrong, it should be like this:
return [["field1", "value1", "="],"AND",["field2","value2","LIKE"]];
And so on!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 24 May, 2020
Answer
1 Likes
Thanks a lot Max, in special your week-end attention, let me share here the final code, for sure will help a lot of people, I had to use "Like" in both where conditions in order to they understand "%"
This topic is locked and no more replies can be posted.