There is a table called Vehicles, where there is a field called “VehicleID”. I need to be able to display these vehicles, but by names.
I already know the names to the VehicleIDs, but it will be impossible for me to change it so that the field holds the name instead of the ID, so instead I just need to change it via PHP when its called up for display.
There not, I have them in a text file on my PC. Basicly in easy terms, I need to do Str_replace 160 times, but dont want to type it out so much. I currently have a text file with:
Then have php sort the $vehicle_list array into the same order that the vehicles are stored in the database. Then use another foreach loop on the $vehicle_list array to do an update (assuming the name field is called name and the table is called vehicle):
foreach ($vehicle_list AS $vehicle ) {
$sq"
UPDATE
vehicle
SET
name='{$vehicle['name']}'
WHERE
car_id = {$vehicle['id']
";
// run query
}
The WHERE clause is a must as you don’t want to overwrite the name each time. You’ll have to adjust the field and table names to match what they are in the database.
If any car names have got spaces in them, they you’ll have to eliminate them spaces (replace the spaces in the names with _ ) but be careful not to eliminate the spaces between the vehicle ID and the vehicle name.
Please not I’ve very little experience working with php and php accessing files (not referring to includes). Once the names are stored in the database then you’d just need to do a relevant SELECT query to get the names of whatever vehicles are required.