clay1 Posted June 5, 2010 Share Posted June 5, 2010 I've got a table with profiles that I need to email to various people based on a list of zip codes provided for example all profiles matching zip codes 1,2, and 3 will be emailed to 123@whatever and all profiles matching zips 4,5 and 6 will be emailed to a different email address. If I grab all the appropriate records from the table with 1 query into an associative array what would be a good way to go through that array, parse the zipcodes and I suppose put them in a new array so that I can email them to the correct address? Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/ Share on other sites More sharing options...
Catfish Posted June 6, 2010 Share Posted June 6, 2010 $sqlQuery = 'YOUR sql QUERY'; if ($recordResults = mysql_query($sqlQuery)) while ($recordData = mysql_fetch_assoc($recordResults)) { if ($recordData['zip'] == 1 || $recordData['zip'] == 2 || $recordData['zip'] == 3) $emailList123[] = $recordData; else if ($recordData['zip'] == 4 || $recordData['zip'] == 5 || $recordData['zip'] == 6) $emailList456[] = $recordData; } else print('Could not fetch results. Query sent was: '.$sqlQuery.'<br/>'."\n"); This code will sort the data with desired zip codes into two arrays $emailList123 and $emailList456 in a format like: $emailList123[fieldname] so to access a fieldname for example, "Name" in the sixth entry you would use: $sixthName = $emailList123[5]['Name']; Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068433 Share on other sites More sharing options...
clay1 Posted June 6, 2010 Author Share Posted June 6, 2010 Great thanks-- that is pretty much how I figured it could be done but arrays give me trouble Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068451 Share on other sites More sharing options...
clay1 Posted June 6, 2010 Author Share Posted June 6, 2010 if ($recordData['zip'] == 1 || $recordData['zip'] == 2 || $recordData['zip'] == 3) $emailList123[] = $recordData; For this part how could I test against an array of zips? in_array? Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068452 Share on other sites More sharing options...
dabaR Posted June 6, 2010 Share Posted June 6, 2010 You mean like this if(in_array($recordData['zip'], array(1, 2, 3))) { ... } ? Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068455 Share on other sites More sharing options...
clay1 Posted June 6, 2010 Author Share Posted June 6, 2010 I guess so? I've got a lot of zips. Typing out record['zip'] == zip1 for every one will be a pretty lengthy file Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068456 Share on other sites More sharing options...
dabaR Posted June 6, 2010 Share Posted June 6, 2010 Oh, OK. Yes that is what you want then. You can read php.net/in_array if you need more examples. Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1068458 Share on other sites More sharing options...
clay1 Posted June 7, 2010 Author Share Posted June 7, 2010 Not sure if I should start a new topic or not but I will try here first So I have the records in separate arrays as such: while ($recordData = pg_fetch_assoc($recordResults)) { if (in_array($recordData['zip'], $birminghamzips)){ $birmingham[] = $recordData;} elseif (in_array($recordData['zip'], $bridgewaterzips)){ $bridgewater[] = $recordData;} I have a script that creates a pdf and sends an email that I have used for a single array that I need to convert so it will send do so for each of these arrays Can I put these arrays into a container array and then use another while loop? something like containerarray = array($zips1, zips2); while ($containerarray){ pdfscript email } Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069206 Share on other sites More sharing options...
dabaR Posted June 7, 2010 Share Posted June 7, 2010 as in http://php.net/array_merge ? Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069212 Share on other sites More sharing options...
clay1 Posted June 7, 2010 Author Share Posted June 7, 2010 (removed extraneous post) Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069216 Share on other sites More sharing options...
clay1 Posted June 7, 2010 Author Share Posted June 7, 2010 as in http://php.net/array_merge ? I mean: $leadsarray = array($birmingham, $bridgewater, $coltsneck, $encino, $grandrapids, $hackensack, $houston, $irvine, $lawrenceville, $la, $nola, $palmbeach, $pittsburgh, $upland); Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069218 Share on other sites More sharing options...
dabaR Posted June 8, 2010 Share Posted June 8, 2010 One emailed PDF per city? Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069228 Share on other sites More sharing options...
clay1 Posted June 8, 2010 Author Share Posted June 8, 2010 One emailed PDF per city? Yes I want to put the profiles in the proper array and then email each array to the correct email address Does that make sense? So birmingham profiles go to [email protected] for example Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069237 Share on other sites More sharing options...
dabaR Posted June 8, 2010 Share Posted June 8, 2010 Yes, that sounds kosher. Especially because I am not Jewish, and have just a vague idea what kosher is. You will be able to make an array of arrays, or two-dimensional array as geeks call it. Quote Link to comment https://forums.phpfreaks.com/topic/203985-selecting-and-sorting-records-by-zipcode/#findComment-1069238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.