Buy Now
Sign in

double search field on ccv6

teldrive , May 20 2020, 22:30
teldrive 559
May 20 2020, 22:30 #392613
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'
Teldrive
admin 28
May 21 2020, 10:18 #392628
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
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
teldrive 559
May 21 2020, 21:07 #392649
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
Teldrive
GreyHead 64
May 22 2020, 08:48 #392656
Hi Teldrive,
The beta version of CFv7 is available from the Blog menu above.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
teldrive 559
May 22 2020, 16:18 #392667
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
Teldrive
healyhatman 9
May 23 2020, 12:56 #392678
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.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
teldrive 559
May 23 2020, 18:59 #392703
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
Teldrive
admin 28
May 24 2020, 00:22 #392709
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
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
teldrive 559
May 24 2020, 08:07 #392714
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;
Teldrive
admin 28
May 24 2020, 09:43 #392718
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
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
teldrive 559
May 24 2020, 11:39 #392724
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 solutionCaptura.JPG
Attachments
Captura.JPG
Captura.JPG
(165.14 KiB)
42 Downloads/Views
Teldrive
admin 28
May 24 2020, 13:37 #392729
"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!
Attachments
Max
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
teldrive 559
May 24 2020, 15:53 #392734
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 )
Captura1.JPG
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
Captura2.JPG

Teldrive
admin 28
May 24 2020, 18:49 #392738
your syntax is wrong, it should be like this:
return [["field1", "value1", "="],"AND",["field2","value2","LIKE"]];
And so on!
Max
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
teldrive 559
May 24 2020, 21:25 #392743
 1
 Answer
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 "%"Captura.JPG
Teldrive