I'm having trouble creating the custom code element to display a list of records. An example of any kind would be very useful to see where I might be going wrong.
Forums
Help with DB Multi Record Loader
Hi Bob,
I know this one is just wrong and just specifying literals, but I have been round the houses!
Apologies for my lack of php understanding.
I'm calling records using this WHERE statement (which I think is correct):
Thanks, Nick
I know this one is just wrong and just specifying literals, but I have been round the houses!
Apologies for my lack of php understanding.
<?php
$x=array('[fname]','[lname]');
foreach ($x as $value)
{
echo $value . "<br />";
}
?>
I'm calling records using this WHERE statement (which I think is correct):
<?php
$user =& JFactory::getUser();
$user_id = $user->id;
?>
`cf_user_id` = '<?php echo $user_id; ?>'
Thanks, Nick
Hi Nick,
Your WHERE code looks ok to me and should load the records submitted by the current logged in user only.
What do you have in the "Model ID" field in the "Multi record loader" settings ? I will assume that you have "Details"
To check if the data is loaded you may use this code in the "custom code" element (or even a custom code action"
If your WHERE statement loads any record then you should find the loaded data under the Mdel ID key which is "Details", if this works fine then you may show me a screenshot for the output and I can tell you how to loop through them.
Regards,
Max
Your WHERE code looks ok to me and should load the records submitted by the current logged in user only.
What do you have in the "Model ID" field in the "Multi record loader" settings ? I will assume that you have "Details"
To check if the data is loaded you may use this code in the "custom code" element (or even a custom code action"
print_r2($form->data);
If your WHERE statement loads any record then you should find the loaded data under the Mdel ID key which is "Details", if this works fine then you may show me a screenshot for the output and I can tell you how to loop through them.
Regards,
Max
Max,
I've had a week away but thank you so much for your help - things seem to be going in the right direction.
I am now displaying a series of Arrays as below and this is the data I would expect to see. So how to loop through them and achieve a simple list?
This is actually just a test device so I can learn how things can be made to work - my real data is rather more complicated. It still seems to be a long way from what I was able to achieve with Chronoconnectivity but I'm hoping that I can get there step by step - when I do, I'll write a tutorial!
Nick
I've had a week away but thank you so much for your help - things seem to be going in the right direction.
I am now displaying a series of Arrays as below and this is the data I would expect to see. So how to loop through them and achieve a simple list?
Array
(
[Itemid] => 553
[option] => com_chronoforms
[view] => form
[Details] => Array
(
[0] => Array
(
[fname] => Nigel
[lname] => Johnson
[published] => 0
)
[1] => Array
(
[fname] => Nicholas
[lname] => Peterson
[published] => 0
)
[2] => Array
(
[fname] => Denis
[lname] => Piper
[published] => 0
)
[3] => Array
(
[fname] => Penelope
[lname] => Garner
[published] => 0
)
)
)
This is actually just a test device so I can learn how things can be made to work - my real data is rather more complicated. It still seems to be a long way from what I was able to achieve with Chronoconnectivity but I'm hoping that I can get there step by step - when I do, I'll write a tutorial!
Nick
Hi Nick,
No problems, I was off for a few days too!🙂
Here is a simple loop:
That should show a list of all first names.
Regards,
Max
No problems, I was off for a few days too!🙂
Here is a simple loop:
<?php
foreach($form->data['Details'] as $detail){
echo $detail->fname;
echo '<br />';
}
That should show a list of all first names.
Regards,
Max
Thank you! Nearly worked - after a bit of tinkering I arrived at the following:
<?php
foreach($form->data['Details'] as $detail){
echo $detail['fname']." ".$detail['lname'];
echo '<br />';
}
?>
Oh, sorry, I forgot that the data is inside an array but not an object 😶
Regards,
Max
Regards,
Max
This topic is locked and no more replies can be posted.