someoneneedshelps
Technical User
Hi Guys,
Im not that bright with php all those hidden functions, I want to open a csv file, get the tope line which is the titles and the rest is data
Do I want two arrays or a two dimensional array, I would then like to compare the titles to the database before creating an insert statement
I then ties together with the above and place a switch inside this function to find the types in order to wrap in quotes or not, thxs in advance
Im not that bright with php all those hidden functions, I want to open a csv file, get the tope line which is the titles and the rest is data
Code:
user,title,subtitle,starts,description,pict_url,category,secondcat,minimum_bid,shipping_cost,shipping_cost_additional,reserve_price,buy_now,auction_type,duration,increment,shipping,payment,international,ends,current_bid,closed,photo_uploaded,quantity,suspended,relist,relisted,num_bids,sold,shipping_terms,bn_only,bold,highlighted,featured,current_fee,tax,taxinc,asking,item_condition,item_manufacturer,item_model,item_colour,item_year
4, 1999 Vauxhall Astra Esate Diesel, Car, 1459934546, <p>\r\n MOT Status Ends : 09 Nov 2016</p>\r\n<p>\r\n Mileage 164409 miles</p>\r\n<p>\r\n Diesel Run for ever isuzu engine astra estate, needs cleaning inside, does not smell but needs a clean hence price. Long mot nov 2016 V5 with me</p>\r\n, test2.jpg, 16, 0, 0.99, 0.00, 0.00, 250.00, 0.00, 1, 21, 0.00, 3, paypal,0, 1461748946, 0.00, 0, 0, 1, 0, 2, 0, 0, n, , n, n, n, n, 0.00, n, y, NULL, Used, vauxhall, astra, blue, 1999
Do I want two arrays or a two dimensional array, I would then like to compare the titles to the database before creating an insert statement
Code:
$types = array(
'user' => 'int',
'title' => 'text',
'subtitle' => 'text',
'starts' => 'time',
'description' => 'text',
'pict_url' => 'image',
'category' => 'int',
'secondcat' => 'int',
'minimum_bid' => 'float',
'shipping_cost' => 'float',
'shipping_cost_additional' => 'float',
'reserve_price' => 'float',
'buy_now' => 'float',
'auction_type' => 'digitnory',
'duration' => 'int',
'increment' => 'float',
'shipping' => 'yorn',
'payment' => 'pay',
'international' => 'yorn',
'ends' => 'int',
'current_bid' => 'float',
'closed' => 'digityorn',
'photo_uploaded' => 'digityorn',
'quantity' => 'int',
'suspended' => 'int',
'relist' => 'int',
'relisted' => 'int',
'num_bids' => 'int',
'sold' => 'yorn',
'shipping_terms' => 'text',
'bn_only' => 'yorn',
'bold' => 'yorn',
'highlighted' => 'yorn',
'featured' => 'yorn',
'current_fee' => 'float',
'tax' => 'yorn',
'taxinc' => 'yorn',
'asking' => 'float',
'item_condition' => 'text',
'item_manufacturer' => 'text',
'item_model' => 'text',
'item_colour' => 'text',
'item_year' => 'text'
);
Code:
function mysql_insert_array($table, $data) {
foreach ($data as $field=>$value) {
$fields[] = '`' . $field . '`';
if (is_array($value)) {
$arr = '';
foreach ($value as $key1=>$value1){
//$arr .= $key1 .'-'. $value1 .'<br>';
}
$values[] = "'" . mysql_real_escape_string($arr) . "'";
} else
$values[] = "'" . mysql_real_escape_string($value) . "'";
}
$field_list = join(',', $fields);
$value_list = join(',', $values);
$query = "INSERT INTO " . $table . " (" . $field_list . ") VALUES (" . $value_list . ")";
return $query;
}
I then ties together with the above and place a switch inside this function to find the types in order to wrap in quotes or not, thxs in advance