Nick"> Linking table data - Forums

Forums

Linking table data

nicholashg 06 Jun, 2011
I'm loading data from 2 tables using Multi Record Loader actions with Model IDs productions and producer.
The WHERE statements are blank for the time being and the form displays a list of Production Titles.

How can I call the related Producer's Name from the producer table in this list?

There are matching fields for the purpose: producer.cf_id = production.producer_cf_id

I tried using the Associated Models option but not sure if that's what it's for?
Perhaps I need to embed a WHERE clause within the foreach loop, but what would this look like?

Just can't get it working …

<?php
$producer = $form->data['producer'];
foreach($form->data['productions'] as $production)
{
echo $production['title'];
//echo $producer['fname']; - how do I link this?
echo "<br />";
}
?>

Nick
nicholashg 09 Jun, 2011
Still struggling with this!
I'm sure the answer lies in the Associated Models settings but I can't figure it.
Just trying to call data from a second table into a list.
Here are my DB Multi Record Loader settings, although I keep changing them!

DB Multi Record Loader 1
DB Field: []
Table: jos_pc_productions
Request Param:
Model ID: production
Fields: []
Load Data: Yes
Enable Associations: No
Associated Models: []
Group Model Data: Yes
WHERE statement: []



DB Multi Record Loader 2
DB Field: []
Table: jos_pc_producers
Request Param:
Model ID: producer
Fields: []
Load Data: Yes
Enable Associations: Yes
Associated Models: production
Group Model Data: Yes
WHERE statement: `cf_id` = `production`.`producer_cf_id`



In other words, cf_id from jos_pc_producers = producer_cf_id from jos_pc_productions
Any chance of some help?

Nick
nicholashg 11 Jun, 2011
Solved with a help from vkeys and Joomla:
http://docs.joomla.org/How_to_use_the_database_classes_in_your_script

<?php
foreach($form->data['production'] as $production){
echo $production['title'].", ";
$db =& JFactory::getDBO();
$producer = $production['producer_cf_id'];
$name_query = "
SELECT ".$db->nameQuote('company')."
FROM ".$db->nameQuote('#__pc_producers')."
WHERE ".$db->nameQuote('cf_id')." = ".$db->quote($producer).";
";
$db->setQuery($name_query);
$producername = $db->loadResult();
echo $producername;
echo "<br />";
}
?>


Thanks vkeys
Nick
This topic is locked and no more replies can be posted.