Page 1 of 1

multiple values in a field of a record

Posted: Tue Apr 20, 2004 7:41 pm
by andycruickshank
I have a table with information on plants, with a field in it called state.

A plant can be in many states, so i have a value in the field 'CA LA WI' and so on, for example. Then, if i'm looking for plants in the area, i select where state like %CA% and get the plants that way, displaying the results with my php page in a table.

Is there a way to delete a value from the field, say, delete LA from the value above?

Thanks

Posted: Tue Apr 20, 2004 7:47 pm
by Unipus
You could dick around with array functions in PHP for a while, but what you really need to do is re-design your database structure so that it uses only atomic (ie, singular) values per field. That's just about the #1 rule of good database design, for reasons precisely like this one.

Posted: Tue Apr 20, 2004 10:28 pm
by litebearer
you might try this

Code: Select all

<?PHP

// get the value from the database
$old = "CA LA MI OR WA ";

// enter the Abbreviation for the state to be removed 
// into a variable -- make sure you include a space
$state = "MI ";
$new = str_replace($state, "", $old);
echo $old;
echo "<br>";
echo $new;
// update the record in the database

?>
be sure to keep a space after EVERY state INCLUDING the last one.


Posted: Tue Apr 20, 2004 11:00 pm
by feyd
why not use a set column type? Frees people from mistyping one, or forgetting things like "always needs a <enter delimiter here> at this spot" kinda stuff.