Filerow | FILENAME | DATE | UploadedContent | '; $query = 'SELECT rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; $results = $wpdb->get_results($query); foreach ($results AS $row) { $content .= '
---|---|---|---|
' . $row->rowid . ' | '; $content .= '' . $row->filename . ' | '; $content .= '' . $row->filedate . ' | '; $content .= '' . $row->rowcontent . ' | '; $content .= '
Inserted the following:
'; $newconcert= []; $query1 = 'SELECT id,rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; $cresults = $wpdb->get_results($query1); foreach ($cresults AS $row) { $rowfileid = $row->id; $resultArray = explode("\t", $row->rowcontent); $band = $resultArray[0]; $venue = $resultArray[1]; $condate = date('Y-m-d', strtotime($resultArray[2])); $ticketlink = $resultArray[3]; $eventlink = $resultArray[4]; //first item in the row should be band $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2]; //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4]; //processing band $bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $band . '"'; $results = $wpdb->get_results($bandsql); if ($results) $newconcert[0] = $results[0]->id; else { $wpdb->insert('wpg_bands', array( 'id' => '', 'wpgband_name' => $band )); echo ($wpdb->last_error); $newconcert[0] = $wpdb->insert_id; } //done processing band //processing venue if (is_numeric($venue)) $newconcert[1] = $venue; else { $venuesql = 'SELECT id FROM wpg_venues WHERE upper(wpgvenue_name)="' . $venue . '"'; $results = $wpdb->get_results($venuesql); if ($results) $newconcert[1] = $results[0]->id; else { $wpdb->insert('wpg_venues', array( 'id' => '', 'wpgvenue_name' => $venue )); echo ($wpdb->last_error); $newconcert[1] = $wpdb->insert_id; } } //done processing venue //not sure how to check dates, hopefully manual verification of files will take care of it //check if concert already exists and return ID if it does. Not checking by date, to be considered $csql = 'SELECT id from wpg_concerts where band = ' . $newconcert[0] . ' and venue = ' . $newconcert[1] . ' and wpgconcert_date ="' . $condate . '"'; $cresults = $wpdb->get_results($csql); if ($cresults) { $usql = 'UPDATE wpg_files SET processed="D", wpgc_id = ' . $cresults[0]->id . ' WHERE id = ' . $rowfileid; $uresults = $wpdb->get_results($usql); $concertlist .= 'DUPLICATE ROW detected BAND ' . $band . ' with band ID ' . $newconcert[0]; $concertlist .= ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1]; $concertlist .= ', CONCERTDATE ' . $condate; $concertlist .= '