<?php
$datetoday = date("Y-m-d");
$path = $modx->getOption('core_path') . 'components/technique/';
$result = $modx->addPackage('technique',$path . 'model/','tec_');
$dbworkshop = $modx->getCollection('workshops', array('date:>=' => $datetoday)); // To get all workshops which will take place in the future
foreach($dbworkshop as $single) {
$zip = $single->get('zip'); // read the zip-code of every object of the workshop-databese
$db2 = $modx->getObject('allzips', array('plz' => $zip)); // get the object for the certain zip-code
$latitude = $db2->get('latitude'); //get the latitude for the zip-code
$longitude = $db2->get('longitude'); //get the longitude for the zip-code
$single->set('latitude',$latitude); // set the latitude
$single->set('longitude',$longitude); // set the longitude
} //end of foreach
$dbworkshop->save(); //save the workshope-database now containing longitude and latitude for each zip-code
return;foreach($dbworkshop as $single) {
$zip = $single->get('zip'); // read the zip-code of every object of the workshop-databese
$db2 = $modx->getObject('allzips', array('plz' => $zip)); // get the object for the certain zip-code
if(is_object($db2) && ($db2)){
$latitude = $db2->get('latitude'); //get the latitude for the zip-code
$longitude = $db2->get('longitude'); //get the longitude for the zip-code
$single->set('latitude',$latitude); // set the latitude
$single->set('longitude',$longitude); // set the longitude
$single->save();
}
} //end of foreach
$single->set('mytableprefix_latitude', $latitude);
echo $latitude . $longitude;
You should first try to get/set some sample content on both tables?
$single->set('zip_db2_latitude','1');$dbworkshop->save(); //save the workshope-database now containing longitude and latitude for each zip-code
But there was something which made me wonder: When adding print_r($single) in the foreach-loop I got a really big output which looked like the complete content of our modx-database. Is this output correct or is this maybe also an error?
print_r($single->toArray());