Extracting data from Arrays in ISAM table
am 20.05.2007 00:20:21 von boclair
--------------050606090306090504070405
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I have a table with between 100k and 200k rows. One field, `names`, is
populated, in each row, with an imploded array of up to 4 names.
I require to create a list of names, without repeats, of all the names
in `names` field to use in an html form.
Any advise would be appreciated. I have no ideas on how to start.
Louise
--------------050606090306090504070405--
Re: Extracting data from Arrays in ISAM table
am 20.05.2007 11:53:08 von itoctopus
Step #1: Select name_field FROM the_table;
Step #2:
$arr_all_names = array();
foreach single_result in your result_set{ //you have to translate this into
php
$arr_name = explode(',', $single_result['name']); //assuming that you
are joining names in the field using a comma
$arr_all_names = $arr_all_names + $arr_name;
}
//remove redundancy
$arr_all_names = array_unique($arr_all_names);
//now sort the array
sort($arr_all_names);
//now all you have to do is to loop through the array to display it on your
site
--
itoctopus - http://www.itoctopus.com
wrote in message news:464F7825.6090200@boclair.com...
>I have a table with between 100k and 200k rows. One field, `names`, is
> populated, in each row, with an imploded array of up to 4 names.
>
> I require to create a list of names, without repeats, of all the names
> in `names` field to use in an html form.
>
> Any advise would be appreciated. I have no ideas on how to start.
>
> Louise
>
>
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Extracting data from Arrays in ISAM table
am 20.05.2007 14:03:51 von Stut
boclair@boclair.com wrote:
> I have a table with between 100k and 200k rows. One field, `names`, is
> populated, in each row, with an imploded array of up to 4 names.
>
> I require to create a list of names, without repeats, of all the names
> in `names` field to use in an html form.
>
> Any advise would be appreciated. I have no ideas on how to start.
The best option would be to normalise the data by breaking the names out
to a separate table. However, if that's not feasible my suggestion is
similar to that itoctopus sent, but a bit more memory efficient.
Inside the loop getting the records, do the following...
foreach (explode(',', $single_result['name']) as $name)
$arr_all_names[$name] = 1;
Then after the loop, to get an array of the names...
$arr_all_names = array_keys($arr_all_names);
-Stut
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php