0

I have a mySQL table which has a field where I keep my arrays in it. So in the table field I have this:

a:2:{i:0;s:10:"XXX1";i:1;s:10:"XXX2";}

I am using this code snippet in PHP to get the field value.

$getCodes = mysql_query("SELECT * FROM foo WHERE bar='$barID'");
while($codeRow = mysql_fetch_array($getCodes))
{
  $code = $codeRow['codes'];
}

When I echo the $code, it prints the full array. How can I print each element on a new line or how can I access specific elements?

3
  • 2
    It is not a good idea to store arrays in a single field. Take a look at Normalization Commented Mar 18, 2012 at 19:03
  • are you storing it in a serialize format? or someother Commented Mar 18, 2012 at 19:11
  • @MostyMostacho - Sometimes there are good reasons to store arrays in a single field. It depends on circumstances. Commented Mar 18, 2012 at 20:31

1 Answer 1

2
$code = unserialize($codeRow['codes']);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.