I'm basically looking开发者_如何学编程 to simply print out each of the allowed values in a CCK field..
i know the allowed values are stored inside a text field within the table: 'content_node_field'.
the values are then stored within 'global_settings'
I'm looking to somehow print out each individual allowed value using a PHP loop.
however with all values being stored within one text field.. im finding it hard to print out each value individually.
Something like this should do the trick.
// Get the global_settings like you described.
$serialized_data = db_result(db_query("..."));
// Unserialize the data.
$unserialized_data = unserialize($serialized_data)
// Foreach the allowed values.
$values = array();
foreach(explode("\n", $unserialized_data['allowed_values']) as $value) {
$values[] = $value;
}
If I am getting your question right, you can create PHP arrays by simply suffixing the []
to the names of the fields, so for example:
<input type="text" name="myname[]" />
Now you can get the values of the array like this:
foreach($myname as $value)
{
echo $value . '<br />';
}
Update Based On Comment:
You can use the json_decode function to convert your data to array and then manipulate accordingly:
Example:
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true));
精彩评论