I am trying to update one table which holds the inputted data from my employees. The table has three columns: entry id, field id, and value. I am wanting to make sure there is a row for every field in the this table according to each entry. As such I have the written the following php/sql script. The thought process was get two arrays (one containing the entry ids and the other the field ids) and check the input table to see if there was an existing row for every field and entry. If not then use an inert into command to add a row with the value 0, but this command is failing. My guess is a timeout error due to the intensity of this function. Any suggestions?
$db = JFactory::getDBO(); $field_query = 'SELECT id FROM `jos_directory_field`'; $db->setQuery( $field_query ); $fields = $db->loadObjectList(); $entry_query = 'SELECT id FROM `jos_directory_entry`'; $db->setQuery( $entry_query ); $entries = $db->loadObjectList(); for($e=0;$e count($entries);$e++) { for($i=0;$i count($fields);$i++) { $insert_query = 'INSERT INTO `jos_directory_enf` (entry_id,field_id,field_value)'; $insert_query .= 'SELECT '.$entries[$e]->id.','.$fields[$i]->id.',0'; $insert_query .= 'FROM dual WHERE NOT EXISTS (SELECT * FROM `jos_directory_enf`'; $insert_query .= 'WHERE entry_id = '.$entries[$e]->id.' and field_id = '.$fields[$i]->id.')'; $db->setQuery( $insert_query ); $db->query(); } }
COMMIT
level are you running under? – Clockwork-Muse