Retrieving record but the column appears to be a string, not array
Hi,
I'm in laravel, working on retrieving a record of a vehicle. Within the record is a column 'vehicle_options' which saves the options of a vehicles like this:
["Driver Side Air Bag","Passenger Air Bag","Side Impact Airbag"] etc. etc.
As part of a form the record is being pulled into, there are a series of checkboxes that need to be checked or not checked depending if the option exists.
Was trying below but I'm thinking the $vehicle->vehicle_options is returning as a string so my code below fails. Any idea where I'm going wrong?
if (in_array("Driver Side Air Bag", $vehicle->vehicle_options)) {echo "found";} else {echo "not found";}
There is no data type array in MySQL, what's stored is a string in a JSON notation.
What is normal is getting a row of an SQL query as an associative array with column names as their key, but not getting an array out of a single column. So somehow this is preprocessed when saving to save that string and you post process that after retrieving it from the database.
Bye, Olaf.
tjyoung
ASKER
I apologize it is very close if not the same. I did however try Ray's fix and find this is happening: