Re: Fetch an element in an array

From: Date: Thu, 08 Jun 2000 16:56:33 +0000
Subject: Re: Fetch an element in an array
References: 1 2  Groups: php.db php.general 
Request: Send a blank email to php-general+get-1314@lists.php.net to get a copy of this message
Richard Lynch wrote: > I dunno for sure, but I would bet you could just use: > > select col2(2), blah blah blah This didn't return anything. > > > or > > select col2[2] blah balh blah This works, but in PHP if I do $row['col2[2]']; instead in an SQL, it won't work. > > > to get that element from PostgreSQL. > > If not, perhaps: > > $col2 = explode(',', $row['col2']); > echo $col2[1]; > Thank you for replying. But how do I get all elements in minimal amount of time: $string='{"Bernie","test","test1"}'; $str1=str_replace('{','',$string); $str2=str_replace('}','',$str1); $str3=str_replace('"','',$str2); $str4=explode(',',$str3); echo $str4[0]; ==> Bernie echo $str4[1]; ==> test echo $str4[2]; ==> test1 I store most of my info in a large field (text[]) array in Postgres. So, it would be slow to do 'select col1[1],col1[2],... from table' if I want to select all info for all rows. table ------ col1 text[] But if I do 'select * from table', I will have to do many str_replace and then an explode as described above. Is there any better way of making it faster? (since I will be storing enormous amount of data, and it can be very slow to query either way. - Bernie

« previous php.general (#1314) next »