Jump to content

Selecting and sorting records by zipcode


clay1

Recommended Posts

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?

 

$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'];

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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.