0

Hello,

I need some help understanding how to display information from the following array and what this method of storage and array is called.

The information held in the database looks like this

{"option1":"1234","option2":"ABCD"}

How do I work with these values? I know how to get the array as a whole but how do I select option1 and the value on its own for example.

If I print the row it shows it as (extended being the field name in the DB)

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

If someone could give some info on what I'm dealing with that would be great.

Thanks.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Kieran Y5
0

Hi,
Your dealing with an array ;)

Assuming your array is named $array all you would need to do it $array;

An example:

echo "Option 1: ".$array['option1']."<br />";
echo "Option 2: ".$array['option2']."<br />";

for($x=1; ( isset($array['option'.$x]) ); $x++)
{
  echo "Option ".$x.": ".$array['option'.$x]."<br />";
}

I hope this was your question ;)

Kieran :)

Edited by Kieran Y5: n/a

0

Unfortunately this hasn't worked. I know I'm dealing with an array but is there a specific term for how they have been stored? The actual values are stored in the mysql database as I posted, see the curly brackets.

{"option1":"1234","option2":"ABCD"}

Anyway the values are blank. What I did try was

$array = $value['extended'];
echo "Option 1: ".$array[token]."<br />";
echo "Option 2: ".$array['paypal']."<br />";

echoing $array shows the following so I don't understand why I cannot simply echo $array

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

Edited by RossCode: n/a

0

Hi,

Arrays are simple to use.

To get the following:

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

You must be using print_r (am I right?);

So, assuming that the array is $array then you should use $array

echo "Option 1: ".$array['extended']['option1']."<br />";
echo "Option 2: ".$array['extended']['option2']."<br />";

for($x=1; ( isset($array['extended']['option'.$x]) ); $x++)
{
  echo "Option ".$x.": ".$array['extended']['option'.$x]."<br />";
}

kieran :)

Edited by Kieran Y5: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.