After creating 2 tables (1 for vehicle types & 1 for vehicle makes) I have got this far:
// connect to and select db here
require_once ('mysql_connect.php');
// define text file
$fileArray = file('Vehicle-Lists.txt');
// loop through lines, parse and insert info to db
foreach ($fileArray as $line) {
preg_match("#^(.*?)\s-\s(.*)#", $line, $matches);
$make = mysql_real_escape_string($matches[1]);
$models = explode(", ", $matches[1]);
$query = "INSERT into Vehicle_Makes VALUES ('', '$make')";
mysql_query($query) or die (mysql_error());
$makeID = mysql_insert_id();
foreach ($models as $model) {
$model = mysql_real_escape_string($model);
$query = "INSERT into Vehicle_Models VALUES ('', '$makeID', '$model')";
mysql_query($query) or die (mysql_error());
}
}
However, It inserted the vehicle make into:
Vehicle_Makes - make
Vehicle_Models - model
Text file is currently in exactly this format:
Austin Healey - 3000, Sprite
Austin Passenger - 1800, Allegro, Ital, Maxi, Mini
Bentley - Corniche, Mulsanne, T Series
In other words, the models havent been inserted.
Can anyone help?