Re: Convert String to Array
| From: | Miles Thompson | Date: | Fri, 30 Sep 2005 14:34:19 +0000 |
| Subject: | Re: Convert String to Array | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-40428@lists.php.net to get a copy of this message | ||
At 12:22 AM 9/30/2005, Ng Hwee Hwee wrote:
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 followLook to your data - why are you storing an array element name matched with a vehicle line? The T100Value appears to be the key field, retrieve it and build your array within your script. Think hard about why we have relational databases -- you are tying a value to a position with this structure. If ever something has to be inserted in the middle everything that follows will be broken, or you will be driven into v. peculiar constructs to solve a problem which could have been avoided up front. On the other hand, I know nothing about your data or your application, o maybe I'm blowing smoke. Regards - Miles ThompsonT100FieldNm T100Value ========== ========= vehMdlCd[0] MER vehMdlCd[1] LEX vehMdlCd[2] TOYand 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