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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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 birmingham@gmail.com for example

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.