views:

664

answers:

2

Hello,

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.

A: 

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));
Sarfraz
Within the field global_settings contains the multiple values.. example:a:4:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:17:"A*ABCDE";s:18:"allowed_values_php";s:0:"";}im looking to output each grade (a, b, c, d, e) and strip the rest away now i know there is str_replace for this however im doing this on multiple fields where the contents do vary.
GaxZE
@GaxZE: Please see my updated answer.
Sarfraz
+1  A: 

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;
}
googletorp
sorry, having a few problems with the foreach loop.getting this error: warning: Invalid argument supplied for foreach() in C:\wamp\www\sites\all\modules\custom\marli\marli.admin.inc on line 11.where it says 'allowed_values' ive put the field 'global_settings' (which containts the data.
GaxZE
@GaxZE Fixed minor flaw in the code, tested it and it works!
googletorp
Sorry to be a complete pain.. how would i be able to store each individual value into a variable? for example:$value = array();$a = $value['a'];$b = $value['b'];i feel like im close to what im trying to achieve!
GaxZE