For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > September 2005 > RE: [PHP-DB] Convert String to Array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] Convert String to Array
Hutchins, Richard

2005-09-30, 7:56 am

Is it possible for you to store the vehMdlCd array as a serialized field in
your database?

I'm not sure how your data is structured, but you would serialize() your
data on the way into the db then unserialize() it when you select it. When
it's unserialized, you'll get it back in the original array format and you
can do with it whatever you please.

Chek out serialize() and unserialize() in the PHP docs and see if that will
work for you.

Rich

-----Original Message-----
From: Ng Hwee Hwee [mailto:hhwee@towa.com.sg]
Sent: Thursday, September 29, 2005 11:23 PM
To: PHP DB List
Subject: [PHP-DB] Convert String to Array


Hi guys,

this looks like a very simple problem but i really have no idea how to do
it.. please help me! thanks!

my MySQL database has a table of which 2 fields are as follow

T100FieldNm T100Value
========== =========
vehMdlCd[0] MER
vehMdlCd[1] LEX
vehMdlCd[2] TOY

and I need to echo out the value for $vehMdlCd[0]...[2]. but when I retrieve
T100FieldNm from the database, PHP recognises it only as a string. Thus, in
order to get the value of $vehMdlCd[0], I need to do the following.

for($i=0; $i<$numOfRows; $i++)
{
$tmpVehMdlCd = "vehMdlCd[$i]";
$vehMdlCd[$i] = $$tmpVehMdlCd;
}

where $numOfRows has been calculated by doing a count of all T100FieldNm
like "vehMdlCd%".

Can someone enlighten me with a simpler way?! Potentially I can have a 100
over different T100FieldNm! =(

I tried using settype and type-casting but still don't get the respective
T100Value! *sob*

Thanks sooo much!

Best regards,
Hwee Hwee

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com