MySQL Forums
Forum List  »  PHP

Storing Array in MySQL column/row
Posted by: Al
Date: May 04, 2005 07:23AM

I want to store an associative array to one column/row but it returns as a string. The only way I was able create the associate array was by exploding the string and using replacement functions (not illustrated below). Is there an easy way to write and call these arrays to MySQL?

Here is a sample associate array:
$month=array("0"=>"Month", "1"=>"January", "2"=>"February", "12"=>"December");

I wrote "0"=>"Month", "1"=>"January", "2"=>"February", "12"=>"December" to the database. (I also tried single quotes, and inserting carriage returns after each set.)

Then I returned it from the database and then put it in an array:

$montharray=$row["somearray"];
$month= array($montharray);

Then I tried to manipulate it, but it treats it as a string:
foreach($month as $key=>$value){
if($key == 2){
echo "<h3>Foreach KEY AND VALUE: $key and $value end</h3>";
} else {echo "<h3>Not equal to 2</h3>";}
}

Options: ReplyQuote


Subject
Written By
Posted
Storing Array in MySQL column/row
Al
May 04, 2005 07:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.