Display datas in relation type : one to many

BigStef 08 Mar, 2013
Hi Bob & Max,
Sorry to bother you with this, but I didn't find any tutorial faor the One to Many relation type. So i did it on my own, and have a problem now :-)
Here's the case :
Users can register to courses of Karate (this my first table), Admin can add Kyu (karate grades) to users.
So I have made a main connection to registration courses... And i'm trying to join the table of Kyu on this main connection. I have activated Multi Tables with One to Many re lation type.
I have activated debugger. So when I call the main connection, I can see that datas are called :

Array
(
    [Approx_Memory_Usage] => 1337976
    [Approx_Time] => 0.0262999534607
    [SQL] => Array
        (
            [0] => SELECT `karateeleve`.* FROM `00_Karate_inscription` AS `karateeleve` WHERE `cf_user_id` = '75' ORDER BY `karateeleve`.`cf_id` LIMIT 0,20
            [1] => SELECT `kyueleve`.* FROM `00_Kyu` AS `kyueleve` WHERE `kyueleve`.`kyu_eleve` IN ('2','4')
        )

    [data] => Array
        (
            [0] => Array
                (
                    [karateeleve] => Array
                        (
                            [cf_id] => 2
                            [cf_uid] => c65461346996baf48eaf21ece7181618
                            [cf_created] => 2013-02-27 19:27:42
                            [cf_modified] => 2013-03-05 21:24:04
                            [cf_created_by] => 75
                            [cf_modified_by] => 75
                            [cf_ipaddress] => 127.0.0.1
                            [cf_user_id] => 75
                            [eleve_nom] => Bob
                            [eleve_prenom] => Bobby
                            [eleve_nomcomplet] => Bob Bobby
                            [eleve_naissance] => 18 Septembre 1986
                            [eleve_poids] => 75
                            [eleve_niveau_inscription] => Débutant - 9e Kyu - Blanche
                            [eleve_sexe] => Masculin
                            [eleve_dojo] => Saint Liboire
                            [eleve_portrait] => 20130302144535_skif_portrait_test.jpg
                        )

                    [kyueleve] => Array
                        (
                            [0] => Array
                                (
                                    [cf_id] => 3
                                    [cf_uid] => 8166e6ee0674239b66c4a0fa6b7d4ef6
                                    [cf_created] => 2013-03-06 20:56:26
                                    [cf_modified] => 0000-00-00 00:00:00
                                    [cf_created_by] => 19
                                    [cf_modified_by] => 0
                                    [cf_ipaddress] => 127.0.0.1
                                    [cf_user_id] => 19
                                    [kyu_date] => 20 Mars 2013
                                    [kyu_eleve] => 2
                                    [kyu_kyu] => 7e Kyu - Orange
                                )

                            [1] => Array
                                (
                                    [cf_id] => 4
                                    [cf_uid] => 5e63504f6e4c641313e0c6449792d031
                                    [cf_created] => 2013-03-06 23:02:13
                                    [cf_modified] => 0000-00-00 00:00:00
                                    [cf_created_by] => 19
                                    [cf_modified_by] => 0
                                    [cf_ipaddress] => 127.0.0.1
                                    [cf_user_id] => 19
                                    [kyu_date] => 08 Mars 2013
                                    [kyu_eleve] => 2
                                    [kyu_kyu] => 5e Kyu - Violette
                                )

                        )

                )

            [1] => Array
                (
                    [karateeleve] => Array
                        (
                            [cf_id] => 4
                            [cf_uid] => 11d0288d3ea6ff16381160a3e26d4aab
                            [cf_created] => 2013-03-04 20:09:16
                            [cf_modified] => 2013-03-05 21:04:55
                            [cf_created_by] => 75
                            [cf_modified_by] => 19
                            [cf_ipaddress] => 127.0.0.1
                            [cf_user_id] => 75
                            [eleve_nom] => Bob
                            [eleve_prenom] => Bobby-La3e
                            [eleve_nomcomplet] => Bob Bobby-La3e
                            [eleve_naissance] => 12 Avril 2006
                            [eleve_poids] => 47
                            [eleve_niveau_inscription] => Débutant - 9e Kyu - Blanche
                            [eleve_sexe] => Féminin
                            [eleve_dojo] => Saint Liboire
                            [eleve_portrait] => 20130304200916_skif_portrait_testenfant.jpg
                        )

                    [kyueleve] => Array
                        (
                        )

                )

        )

)

In this example, first row has 2 kyu, and 2nd row has no kyu... But I can't display the 2 kyu of the 1st user in my custom table. I have tried with :
{kyueleve.kyu_kyu} and with {kyu_kyu} , knowing that kyu_kyu is the grade...
The fact that the debugger show the datas certifie me that I have this datas, isn't ? I'm missing something here, but don't know what... Any idea ?
GreyHead 09 Mar, 2013
Hi BigStef,

I'm not clear how this is supposed to work in CC :-(

I'd try something like this:
$row['kyueleve']['kyu_kyu']


Bob
Max_admin 10 Mar, 2013
Hello,

for multiple records you need to use this:

{kyueleve.[n].kyu_kyu}
that will simply display the 2 values (in your case 2 only) concatenated by a comma (you can configure the separator in the connection settings).

You may also use
{kyueleve.0.kyu_kyu}
to display the first record value, since you have specified the path.

for PHP:
$row['kyueleve'][0]['kyu_kyu']
or loop through the list if you want to get them all using PHP😉

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
BigStef 11 Mar, 2013
Hi Max and thanks, that's what I needed !
Just a little thing...
I noticed that the "Array values merger" doesn't work anymore when i use this on my custom Table (works great on auto listing). Is that because I have to enter some code somewhere else ?

PS : Be sure that i look on forum before asking that kind of question, i'm not far from knowing the CC category by heart :-)
Max_admin 13 Mar, 2013
Hi Stef,

I think that it should work fine in both, as long as the value returned is a 1 dimension array then it should work, what did you use exactly in the custom listing ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
BigStef 14 Mar, 2013
Hi Max,
I first tried with a comma, wich is the default value there... Then with the <br /> tag wich would be the best to fit here. Works when listing is auto (last column - Kyu) :
[attachment=1]screenshot_auto.jpg[/attachment]
But no more when when i use my custom table (last column - Niveau actuel) :
[attachment=0]screenshot_custom.jpg[/attachment]
For info, i'm using custom table to display users thumbnail...

Edit : If Bob see this screenshot : I'm using Max, Jim and Bob as test for a long time now, since my first CC form in fact, so do not take umbrage :-)
Max_admin 15 Mar, 2013
Hi Stef,

Well, ok, please try to concatenate them manually in the list then, for example, instead of using this:
{kyueleve.[n].kyu_kyu}


try to extract the values of the array using PHP.

But I think that there is something wrong here, if the column value was still an array then you would get the word "Array" in there, however, you have the values, please try to use comma "," as the merger and see if it works in custom listing ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Bullfn33 21 Sep, 2013

Hello,

for multiple records you need to use this:

{kyueleve.[n].kyu_kyu}
that will simply display the 2 values (in your case 2 only) concatenated by a comma (you can configure the separator in the connection settings).

You may also use
{kyueleve.0.kyu_kyu}
to display the first record value, since you have specified the path.

for PHP:
$row['kyueleve'][0]['kyu_kyu']
or loop through the list if you want to get them all using PHP😉

Regards,
Max


Hi Max or anyone,

I'm trying the third option, using PHP to loop through an array in a one-to-many relational CC using a custom listing. However, I cannot get anything to show up using the third option you wrote above, not even the array itself so I can't loop through the results. I can show the array using the first two examples so I know it is there but I need the PHP format in order to loop through the array.

First task, display the array using PHP format. This is what I try
<tr>
<td style="text-align: center;"><?php echo $row['P'][n]['h_score'] ?></td>
</tr>

I also tried different syntaxes
$row['P']['n']['h_score']
$row['P'][N]['h_score']
$row['P'].[n].['h_score']

This will show the first record
$row['P'][0]['h_score']

This shows nothing
$row['P']['h_score']


So what is the correct way to display an array using the PHP option?

much thanks
GreyHead 21 Sep, 2013
Hi Bullfn33,

If this displays the first record:
$row['P'][0]['h_score']
Then I think that this should loop through them all:
<?php
foreach ( $row['P'] as $k => $v ) {
  echo $v['h_score'];
}
?>

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger