Hi Phil,
Can you give me a bit more info about what you want the in_array() code to do? I can't see what you want the resulting query to be.
Bob
Hi Bob,
The present method with return $array works very well when there is only a single value in the column (fields) . Lets say when column field3 or field 4, etc do contain only a single value could it be numeric or alphanumeric.
But what about when one of the column contains a string of concatenated values ?
For example if fields 3 contains " ab1" and field4 contains: " bc1,bc2,bc3,bc4,bc5, ...." how would you handle field 4 ? with return $array method ?
I have tried via in_array, or building some mysql queries or FIND_ IN_SET, or LIKE %aaa%, etc, following the tuto about WHERE conditions but not success !.
<?php
$array = array(); // empty results array
$lang = JFactory::getLanguage();
$array['language'] = $lang->getTag();
$cols_array = array(
'status' => 'field2_select',
'field3' => 'field3_select',
'field4' => 'field4_select', >>>>>> If this column contains a string of values ? for example
// more column => inputs here
);
foreach ( $cols_array as $k => $v ) {
if ( isset( $form->data[$v] ) && $form->data[$v] ) {
$array[$k] = $form->data[$v];
}
}
return $array;
?>
Best,
Phil
Hi Phil,
For "LIKE", just use this in your array:
"field4 LIKE" => "%value%"
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
HI Max,
i have tried the " field4 LIKE" => "%value% " but did got the expected results.
Maybe my initial question was not clear enough. (in the meantime i changed also a little bit the structure of the db).
What i am trying to do indeed is to find an alternative to an " explode " function followed by " for if " for comparison purposes of the content of a colum field " $select['column_id'] " in a database with an input " $form->data['selected_value'] " .
$select['column_id'] will contain an array of alphanueric values let say " " ab1,ab2,ab3,ab4,ab5,...., ...."
$form->data['selected_value'] could be empty or contain one of the " ab1,ab2,ab3,ab4,ab5, ... , ...." alphanumeric values let say " ab3 " for example .
Classic method would be getting the values to analyse via a dbread action ( which works well ):
foreach($form->data['SelectResults'] as $select):
$result=explode(',',$select['column_id']);
if ($form->data['selected_value']) {
for ($i = 0; $i < count($result); $i++) { if ($result[$i] == $form->data['selected_value']) {
do something ; } } } .... etc
I am trying to find out if with the "array method"; the same stuf could be done without " foreach " "explode" and " if for "
Reason is that there are several selectors and possible choices which leads to a long list of " for if do_ something ".
Best Regards,
Phil
Hi Phil,
You are trying to select records which has the $form->data['selected_value'] string, correct ?
If yes then you need a LIKE, and my code should work, please check the debug results or post it.
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?