Page 1 of 1

store array

Posted: Thu Jul 22, 2004 1:37 am
by jiggy1com
feyd | Please use

Code: Select all

tags when posting code.  Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


can you store an array in a mysql db, and retrieve it and use it as an array? (does the field need to be TEXT or something special?)

when i use phpmyadmin i see the value is Array basically saying i have an array stored in there -- that's fine. when i pull it out and echo it, i get Array again; that makes sense. 

if i count($array) i get 1, or whatever number of items it has.

however, when i try to loop the array it doesn't run the loop. any ideas??

see code:

Code: Select all

while($question = mysql_fetch_object($run_form_data))
		{
			while($chosethis = mysql_fetch_object($run))
			{				
			$here = eval("return \$chosethis->question_{$question->formdataid};");
			print $here;	// prints "Array"				
			print count($here);	// prints "1"		
				foreach($here as $temp)
				{						
				print "[".$temp."]"; // is never run, i never see "[]"
                                }
			}
		}


feyd | Please use

Code: Select all

tags when posting code.  Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Jul 22, 2004 1:50 am
by feyd
you're storing the string, "Array", nothing more.. use [php_man]serialize[/php_man]() to compact the array into a string. To expand it back, use [php_man]unserialize[/php_man]().

thkx

Posted: Thu Jul 22, 2004 2:06 am
by jiggy1com
thanks - i dont think im storing a string ... im storing ... i have checkboxes with the same name, when submitted php creates an array, correct? that's what's stored.

i'll try what you recommended and that sounds like it'll work.

sorry for not using <?php ?> -- this being a PHP site i thought i could omit them :)

...

Posted: Thu Jul 22, 2004 2:15 am
by feyd
you can test if you are storing a string or not by switching "print $here;" to "var_dump($here);"

delayed thanks!

Posted: Wed Aug 04, 2004 1:00 am
by jiggy1com
hey i know its been some time but i just got back to working on this thing.

looks like your suggestions payed off: serialize(), store data, retrieve data, unserialize() ... now i can work with it.

thanks!!!!!