and ModelID 'Menu'. First step is ok, it works. I can show data from this arrow.But no suscess, if I use in DBread#2 Condition field next code: $form->data['Menu'][0]['soup1']);?> $form->data['Menu'][0]['soup2']);?> $form->data['Menu'][0]['salad1']);?>Actually, if I try use in Custom next:data['Meals'][0]['price'];echo $form->data['Meals'][1]['price'];?>nothing happens. But if I`m using the quotes ' ' around the $form[] in Conditions field: '$form->data['Menu'][0]['soup1']');?> '$form->data['Menu'][0]['soup2']');?> '$form->data['Menu'][0]['salad1']');?>it works, Custom field shows data, but with error:"Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/......../administrator/components/com_chronoforms5/chronoforms/actions/db_read/db_read.php(67) : eval()'d code on line 2".Can anyone help me? Something wrong with synthax, or there is another way to make this form, using php and CF 5 features?Thnx in advance for some snippets."> CF v5 multiple conditions in DBread - Forums

Forums

CF v5 multiple conditions in DBread

ikub 28 Jan, 2015
Hi, everyone.
Need help🙂 . I`m building a form for meals delivery service. On the page1 customer puts in delivery date, on page2 he can see menu set for the date (in tabs) with dish names, images, igredients, calories, etc. Form uses data from two tables. The first one includs dates and uniq id`s of menu elements for each date:

id------date--------salad1--salad2--soup1--soup2 ...
1---2015-03-01-----s6--------s2-------u1------u8 ...

The second one has dish details:

id---uniq_id---naimenov---price-------ingred-------------image
1------s1----------Greek-----8,30------Cheese,...-------.../12.jpg
....
27----b10---------Tea-------1,30-----Tea,sugar,...------.../24.jpg

Now I need to return all rows from second DB, where uniq_id=uniq id of the meal, and find for each dish prices, ingredients, etc., to place them into Custom fields of the form.
I put two DBread actions, first one with string in condition field:
<?php
return array('Menu.date' => $form->data["deliverydate"]);
?>

and ModelID 'Menu'. First step is ok, it works. I can show data from this arrow.
But no suscess, if I use in DBread#2 Condition field next code:
<?php
return array('uniq_id' => $form->data['Menu'][0]['soup1']);
?>
<?php
return array('uniq_id' => $form->data['Menu'][0]['soup2']);
?>
<?php
return array('uniq_id' => $form->data['Menu'][0]['salad1']);
?>

Actually, if I try use in Custom next:
<?php
  echo $form->data['Meals'][0]['price'];
echo $form->data['Meals'][1]['price'];
?>

nothing happens. But if I`m using the quotes ' ' around the $form[] in Conditions field:
<?php
return array('uniq_id' => '$form->data['Menu'][0]['soup1']');
?>
<?php
return array('uniq_id' => '$form->data['Menu'][0]['soup2']');
?>
<?php
return array('uniq_id' => '$form->data['Menu'][0]['salad1']');
?>

it works, Custom field shows data, but with error:
"Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/......../administrator/components/com_chronoforms5/chronoforms/actions/db_read/db_read.php(67) : eval()'d code on line 2".
Can anyone help me? Something wrong with synthax, or there is another way to make this form, using php and CF 5 features?
Thnx in advance for some snippets.
Max_admin 28 Jan, 2015
Hi ikub,

After the first "DB Read", please use a Debugger action, what do you get ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
ikub 28 Jan, 2015
Hi, Max!
Data Array:
Array
(
    [option] => com_chronoforms5
    [chronoform] => multitable2php
    [event] => submit
    [tvout] => ajax
    [deliverydate] => 2015-03-10
    [company] => we
    [address] => er
    [contname] => rt
    [conttel] => +8(888)888-8888
    [contmail] => 1@1.ru
    [qtperson] => 5
    [details] => Далее
    [Menu] => Array
        (
            [0] => Array
                (
                    [id] => 38
                    [date] => 2015-03-10
                    [daytype] => vt1
                    [salad1] => s3
                    [salad2] => s9
                    [soup1] => u3
                    [soup2] => u9
                    [dish1] => d3
                    [dish2] => d4
                    [garnir1] => g4
                    [garnir2] => g5
                    [garnir3] => g6
                    [bewerage1] => b2
                    [bewerage2] => 
                    [sweet1] => w1
                    [sweet2] => w2
                    [sweet3] => w3
                    [bulka1] => c1
                )

        )

)

Array:
Array
(
)

Errors:
Array
(
)

Debug info:
Array
(
    [7] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Menu`.`id` AS `Menu.id`, `Menu`.`date` AS `Menu.date`, `Menu`.`daytype` AS `Menu.daytype`, `Menu`.`salad1` AS `Menu.salad1`, `Menu`.`salad2` AS `Menu.salad2`, `Menu`.`soup1` AS `Menu.soup1`, `Menu`.`soup2` AS `Menu.soup2`, `Menu`.`dish1` AS `Menu.dish1`, `Menu`.`dish2` AS `Menu.dish2`, `Menu`.`garnir1` AS `Menu.garnir1`, `Menu`.`garnir2` AS `Menu.garnir2`, `Menu`.`garnir3` AS `Menu.garnir3`, `Menu`.`bewerage1` AS `Menu.bewerage1`, `Menu`.`bewerage2` AS `Menu.bewerage2`, `Menu`.`sweet1` AS `Menu.sweet1`, `Menu`.`sweet2` AS `Menu.sweet2`, `Menu`.`sweet3` AS `Menu.sweet3`, `Menu`.`bulka1` AS `Menu.bulka1` FROM `qvrqa_chronoengine_chronoforms_datatable_menudays` AS `Menu` WHERE `Menu`.`date` = '2015-03-10'
                        )

                )

        )

)

Thank you for fast reply!
Max_admin 28 Jan, 2015
Data looks ok, and your code earlier should work fine, assuming you have a field named "uniq_id" in the 2nd table and it may has a value matching the "salad1" field value.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Max_admin 29 Jan, 2015
Ah yes, the line below has a problem:
return array('uniq_id' => '$form->data['Menu'][0]['soup1']');

should be:
return array('uniq_id' => $form->data['Menu'][0]['soup1']);


Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
ikub 29 Jan, 2015
Yeah, Max,
But in this case:
return array('uniq_id' => $form->data['Menu'][0]['soup1']);

it returns only 1 row from the table. I mean if I put several strings of such synthax in "Conditions" field, it returns only 1 row.
And this:
return array('uniq_id' => '$form->data['Menu'][0]['soup1']');

returns several rows, but with synthax error alert. Maybe there is some bug?
Today I made much of form functionality, but I had to use 15 DB Read`s instead of 15 conditions in 1 DB Read (((.
Is there another way?
Regards,
ikub.
Max_admin 29 Jan, 2015
If I understand your requirements correctly then you should do this:

#1- set the "Multi read" in the first "db read" to "No", because you only need 1 menu selected.

#2- change all your code later to not include the "[0]"

#3- Since you need to read all records matching the menu plates, you can use an IN statement:

return array('uniq_id' => array($form->data['Menu']['soup1'], $form->data['Menu']['soup2'], $form->data['Menu']['salad1']));


And add all the fields to the list above.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.