php - What is the best way to store large amounts of data in an array? -


i have database of 100,000 contacts.

i have multiple select box use select contacts add specific mailing list.

my problem storing data mailing list in serialized array format (php) in mysql.

when select on number of contacts, seems break (i assume not enough memory) , not update array.

is there best way store large array in mysql , there best way keep memory usage in php array() low?

code example

if(isset($_post['add'])) {     $name = $core->escapestring($_post['name']);     $desc = $core->escapestring($_post['desc']);     foreach($_post['addselect'] $null => $id) {         if(!in_array($id, $recipientarray)) {             $recipientarray[] = $id;         }     }     $contacts->updateml($lid, $name, $desc, serialize($recipientarray)); } else if(isset($_post['rm'])) {     $name = $core->escapestring($_post['name']);     $desc = $core->escapestring($_post['desc']);     foreach($recipientarray $null => $id) {         foreach($_post['rmselect'] $null1 => $id1) {             if($id == $id1) {                 unset($recipientarray[$null]);             }         }     }     $contacts->updateml($lid, $name, $desc, serialize($recipientarray)); } 

updateml function

//class 3, function 16 function updateml($lid = '', $name = '', $desc = '', $recip = '') {     global $mysqli;     $query = "update `mailing_lists` set `name` = '".$name."', `desc` = '".$desc."', `recipients` = '".$recip."' `list_id` = '".$lid."' limit 1";     $commit = $mysqli->query($query);     if($commit == false) {         die("issues database detected. please email peter@domain.com quoting error code: <strong>class3/16.1</strong>.");     }     else     {         return true;     } } 

you need 2 tables. 1 mailing list definition, 1 recipients. in recipients table you'd need have foreign key relating record appropriate mailing list.

so mailing_lists table looks this:

ml_id name desc 

and recipients looks this:

r_id email ml_id 

first add mailing list database:

insert mailing_lists set name = 'my first list', desc = 'mailsareus' 

when add new recipients add new row recipients table:

insert recipients set email = 'xxx@mail.com', ml_id = 1 

if need recipients , definition mailing list use join

select * mailing_lists join recipients on recipients.ml_id = mailing_lists.ml_id 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -