Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do a number of things.</p> <ul> <li><a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" rel="nofollow noreferrer">on duplicate key</a> instead of select</li> <li><a href="http://www.php.net/manual/en/pdo.prepare.php" rel="nofollow noreferrer">prepared statement</a> if you have access to PDO MySQL.</li> <li><a href="http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html" rel="nofollow noreferrer">stored procedure</a> in MySQL</li> </ul> <p>Try This. I'm unable to test it but the syntax should be right.</p> <pre><code>$counter = 0; $events = sizeof($feed_array['1']) - 1; while($counter &lt;= $events ) { $eventDate = explode("/", $feed_array['1'][$counter]); //print_r($eventDate); $eventTime = explode(":", $feed_array['2'][$counter]); //print_r($eventTime); $eventUnixTime = mktime($eventTime[0], $eventTime[1], "00", $eventDate[1], $eventDate[0], $eventDate[2]); $data = array( 'eventtime' =&gt; $eventUnixTime, 'eventname' =&gt; addslashes($feed_array['3'][$counter]), 'venuename' =&gt; addslashes($feed_array['4'][$counter]), 'venueregion' =&gt; addslashes($feed_array['5'][$counter]), 'venuepostcode' =&gt; addslashes($feed_array['6'][$counter]), 'country' =&gt; addslashes($feed_array['7'][$counter]), 'minprice' =&gt; addslashes($feed_array['8'][$counter]), 'available' =&gt; addslashes($feed_array['9'][$counter]), 'link' =&gt; addslashes($feed_array['10'][$counter]), 'eventtype' =&gt; addslashes($feed_array['11'][$counter]), 'seaOnSaleDate' =&gt; addslashes($feed_array['12'][$counter]), 'perOnSaleDate' =&gt; addslashes($feed_array['13'][$counter]), 'soldOut' =&gt; addslashes($feed_array['14'][$counter]), 'eventImageURL' =&gt; addslashes($feed_array['15'][$counter]), 'perfID' =&gt; addslashes($feed_array['16'][$counter]), ); $update = array(); foreach ($data as $key =&gt; $value) $update[] = "`$key` = '$value'"; $sql = "INSERT INTO `dante_tickets`.`it_raw`" . '(`id`, `'. implode ('`,`', array_keys($data)) . '`) VALUES ' . '(NULL, ' . implode (',', $data) . ') ON DUPLICATE KEY UPDATE ' . implode (',', $update); mysql_query($sql) or die(mysql_error().":".$sql); echo "Inserted or Updated".$feed_array['16'][$counter].": ".addslashes($feed_array['3'][$counter])."\n"; unset($sql); $counter++; } </code></pre> <p>I forgot to mention this requires that perfID is a unique key.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload