Forums

question on table joins

chrissy6930 16 Jun, 2011
hi all,

when following a linked title (with $detail['cf_id'] being posted) of an entry the detail page of the respective entry would be displayed.
there are 2 tables: events and venues
field locid in table events is identical to field cf_id of table venues

the logic I need would be something like this:
$sql = 'SELECT e.*, v.* FROM #__chronoforms_data_events AS e'
      .' INNER JOIN #__chronoforms_data_venues AS v ON e.locid = v.cf_id'
      .' WHERE e.cf_id =  '. $detail['cf_id'];

only how am I to set this up ?

J!1.5.23, CF 4 RC 1.9
Max_admin 20 Jun, 2011
Hi Chrissy,

You need 2 Multi record loader actions, one for each table, one of them will have "load data" set to "no" and "enable associations" to "yes" and you will give 2 different Model IDs for both actions and will write each one in the other's "associated models" box, lastly you will need to write the Join case in the Where box of the main one (loading the data)

please try it or let me know and I can show you a demo/screen shot

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
chrissy6930 20 Jun, 2011
Hi MAx,

thanks for the hints!🙂

I'm a bit confused though:
main record loader = the one loading events table
1.
quote: one of them will have "load data" set to "no" and "enable associations" to "yes"
the main one?
and the other one ? both enabled ? both disabled ?
2.
quote: need to write the Join case in the Where box of the main one
if I write the join case (ON e.locid = v.cf_id) into the where clause wouldn't that mean
WHERE ON e.locid = v.cf_id ? :?
and how am I to translate ON e.locid = v.cf_id ?
should I use something like
ON Events.locid = Venues.cf_id ?
with Events / Venues being the Model IDs?
Max_admin 21 Jun, 2011
Hi Chrissy,

Let me give you an example, I want to load the data for all Categories under section id = 3 (J1.5 website), and under each category record I want a list for articles and the section to which the category belongs, so I have this:

#1- DBMRL (DB Multi record loader) connected to table "jos_sections"
Model ID -> Section
Load data & Enable associations -> No
Fields -> id,title,name,alias (OPTIONAL)

#2- DBMRL connected to table "jos_categories"
Model Id -> Category
Load Data & Enable associations -> Yes
Associated Models -> Section,Article
Where -> Category.section = Section.id AND Category.section='3' AND Category.id = Article.catid

#3- DBMRL connected to table "jos_content"
Model ID -> Article
Load data & Enable associations -> No

And here is an example output using print_r2($form->data):


Array
(
    [option] => com_chronoforms
    [chronoform] => multi-data
    [Itemid] => 
    [Category] => Array
        (
            [0] => Array
                (
                    [id] => 28
                    [parent_id] => 0
                    [title] => Current Users
                    [name] => 
                    [alias] => current-users
                    [image] => 
                    [section] => 3
                    [image_position] => left
                    [description] => Questions that users migrating to Joomla! 1.5 are likely to raise

                    [published] => 1
                    [checked_out] => 0
                    [checked_out_time] => 0000-00-00 00:00:00
                    [editor] => 
                    [ordering] => 2
                    [access] => 0
                    [count] => 0
                    [params] => 
                    [Section] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [title] => FAQs
                                    [name] => 
                                    [alias] => faqs
                                )

                        )

                    [Article] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 11
                                    [title] => How do I upgrade to Joomla! 1.5 ?
                                    [alias] => how-do-i-upgrade-to-joomla-15
                                )

                            [1] => Array
                                (
                                    [id] => 13
                                    [title] => What happened to the locale setting?
                                    [alias] => what-happened-to-the-locale-setting
                                )

                            [2] => Array
                                (
                                    [id] => 16
                                    [title] => Only one edit window! How do I create "Read more..."?
                                    [alias] => only-one-edit-window-how-do-i-create-read-more
                                )

                            [3] => Array
                                (
                                    [id] => 32
                                    [title] => Where is the Static Content Item?
                                    [alias] => where-is-the-static-content
                                )

                            [4] => Array
                                (
                                    [id] => 36
                                    [title] => Where did the Installers go?
                                    [alias] => where-did-the-installer-go
                                )

                            [5] => Array
                                (
                                    [id] => 37
                                    [title] => Where did the Mambots go?
                                    [alias] => where-did-the-mambots-go
                                )

                        )

                )

            [6] => Array
                (
                    [id] => 27
                    [parent_id] => 0
                    [title] => New to Joomla!
                    [name] => 
                    [alias] => new-to-joomla
                    [image] => 
                    [section] => 3
                    [image_position] => left
                    [description] => Questions for new users of Joomla!
                    [published] => 1
                    [checked_out] => 0
                    [checked_out_time] => 0000-00-00 00:00:00
                    [editor] => 
                    [ordering] => 3
                    [access] => 0
                    [count] => 0
                    [params] => 
                    [Section] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [title] => FAQs
                                    [name] => 
                                    [alias] => faqs
                                )

                        )

                    [Article] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 31
                                    [title] => Is it useful to install the sample data?
                                    [alias] => is-it-useful-to-install-the-sample-data
                                )

                            [1] => Array
                                (
                                    [id] => 39
                                    [title] => How do I remove an Article?
                                    [alias] => how-do-i-remove-an-article
                                )

                            [2] => Array
                                (
                                    [id] => 40
                                    [title] => What is the difference between Archiving and Trashing an Article? 
                                    [alias] => what-is-the-difference-between-archiving-and-trashing-an-article
                                )

                        )

                )

            [9] => Array
                (
                    [id] => 31
                    [parent_id] => 0
                    [title] => General
                    [name] => 
                    [alias] => general
                    [image] => 
                    [section] => 3
                    [image_position] => left
                    [description] => General questions about the Joomla! CMS
                    [published] => 1
                    [checked_out] => 0
                    [checked_out_time] => 0000-00-00 00:00:00
                    [editor] => 
                    [ordering] => 1
                    [access] => 0
                    [count] => 0
                    [params] => 
                    [Section] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [title] => FAQs
                                    [name] => 
                                    [alias] => faqs
                                )

                        )

                    [Article] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 12
                                    [title] => Why does Joomla! 1.5 use UTF-8 encoding?
                                    [alias] => why-does-joomla-15-use-utf-8-encoding
                                )

                            [1] => Array
                                (
                                    [id] => 14
                                    [title] => What is the FTP layer for?
                                    [alias] => what-is-the-ftp-layer-for
                                )

                            [2] => Array
                                (
                                    [id] => 15
                                    [title] => Can Joomla! 1.5 operate with PHP Safe Mode On?
                                    [alias] => can-joomla-15-operate-with-php-safe-mode-on
                                )

                            [3] => Array
                                (
                                    [id] => 17
                                    [title] => My MySQL database does not support UTF-8. Do I have a problem?
                                    [alias] => my-mysql-database-does-not-support-utf-8-do-i-have-a-problem
                                )

                            [4] => Array
                                (
                                    [id] => 25
                                    [title] => What are the requirements to run Joomla! 1.5?
                                    [alias] => what-are-the-requirements-to-run-joomla-15
                                )

                            [5] => Array
                                (
                                    [id] => 28
                                    [title] => How do I install Joomla! 1.5?
                                    [alias] => how-do-i-install-joomla-15
                                )

                            [6] => Array
                                (
                                    [id] => 33
                                    [title] => What is an Uncategorised Article?
                                    [alias] => what-is-uncategorised-article
                                )

                            [7] => Array
                                (
                                    [id] => 35
                                    [title] => Is it possible to change A Menu Item's Type?
                                    [alias] => is-it-possible-to-change-the-types-of-menu-entries
                                )

                        )

                )

            [17] => Array
                (
                    [id] => 32
                    [parent_id] => 0
                    [title] => Languages
                    [name] => 
                    [alias] => languages
                    [image] => 
                    [section] => 3
                    [image_position] => left
                    [description] => Questions related to localisation and languages
                    [published] => 1
                    [checked_out] => 0
                    [checked_out_time] => 0000-00-00 00:00:00
                    [editor] => 
                    [ordering] => 4
                    [access] => 0
                    [count] => 0
                    [params] => 
                    [Section] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [title] => FAQs
                                    [name] => 
                                    [alias] => faqs
                                )

                        )

                    [Article] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 10
                                    [title] => How do I localise Joomla! to my language?
                                    [alias] => how-do-i-localise-joomla-to-my-language
                                )

                            [1] => Array
                                (
                                    [id] => 29
                                    [title] => What is the purpose of the collation selection in the installation screen?
                                    [alias] => what-is-the-purpose-of-the-collation-selection-in-the-installation-screen
                                )

                            [2] => Array
                                (
                                    [id] => 30
                                    [title] => What languages are supported by Joomla! 1.5?
                                    [alias] => what-languages-are-supported-by-joomla-15
                                )

                            [3] => Array
                                (
                                    [id] => 34
                                    [title] => Does the PDF icon render pictures and special characters?
                                    [alias] => does-the-pdf-icon-render-pictures-and-special-characters
                                )

                            [4] => Array
                                (
                                    [id] => 38
                                    [title] => I installed with my own language, but the Back-end is still in English
                                    [alias] => i-installed-with-my-own-language-but-the-back-end-is-still-in-english
                                )

                        )

                )

        )

)

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
chrissy6930 21 Jun, 2011
Hi MAx,

thanks for the instructions!

I must still be missing something as the array is empty:

#1 DCMRL
DB Field : cf_id
Table: jos_chronoforms_data_events
Request Param: id
model ID : Event
Load Data & Enable Associations: yes
Associated Models: Venue
WHERE statement: Event.locid = Venue.cf_id

#2 DCMRL
Table: jos_chronoforms_data_venues
model ID : Venue
Load Data & Enable Associations: no
Associated Models: Event

print_r2($form->data) returns this:
Array (
    [option] => com_chronoforms
    [chronoform] => eventdetails
    [id] => 3
    [Itemid] => 62
    [Event] => Array ()
)
This topic is locked and no more replies can be posted.