php crew...need help again

Discussion in 'OT Technology' started by Leb_CRX, Apr 28, 2006.

  1. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    one of my clients has franchies dedicated to ranges of postal codes (cdn zip code)...a user of the website enters a certain postal code, it tells them which franchise they go to...1, 2, or null (head office)

    so for example

    k1e-1m4
    k1e-1m5
    k1e-1m6
    belong to franchise 1

    k1c-1m4
    k1c-1m5
    k1c-1m6
    belong to franchise 2

    to me, the best way is to use a 2 dimentional array for this (keep in mind the liting of postal codes is gonna be huge)...first dimension is relative to the franchise, secondary being the actual postal codes...

    big_array[0][0] = "k1e-1m4,k1e-1m5,k1e-1m6";
    big_array[1][0] = "k1c-1m4,k1c-1m5,k1c-1m6";

    and do a nested loop to search and locate which franchise belongs to what...pretty straight forward...the ONLY reason I think a 2d array is required is in case the array gets maxed out ... and I can't seem to find an answer if an array has a maximum amount of data it can hold or not.

    is there a better way to do this? can php arrays infinite amount of data in an array? any help would be good :eek3:
     
  2. mads.

    mads. OT Supporter

    Joined:
    May 19, 2002
    Messages:
    26,805
    Likes Received:
    0
    Location:
    Toronto, Canada
  3. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    I think the size of an array is limited by the amount of RAM in a system, and the size of an integer used as the key.

    Why not use a MySQL table? Faster query, and MUCH better on RAM consumption...

    Or why not use a programatic approach to determining which office to go to?
     
  4. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    I want something simple...this wont be a high traffic site

    I thought about mysql but the server it resides on doesn't contain a mysql server, but i'll double check

    thanks
     
  5. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    How much data are you talking about? If you only have a small amount of codes to worry about, then storing the data in the page should be ok. But if its a good amount, you will want to keep in mind for each and every page load, the server has to parse your script and toss it in memory. You're working with static data that probably doesn't change much. If you can't swing it into a database, you might think about storing the data in a file (or files).
     
  6. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    not too much

    say about 100 postal codes....for about 15 clients right now

    I don't know if that would be considered a lot or not :o
     
  7. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    why bother putting it all in an array if its giving you trouble? just do a if posted value equals x or y or z go to a page. granted its messy with a lot of values that may need to be updated but it will work if you cannot use a database
     
  8. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,278
    Likes Received:
    555
    You could always code your script to read and parse a text file...
    Your text file would look like this:

    F1:k1e-1m4,k1e-1m5,k1e-1m6
    F2:k1c-1m4,k1c-1m5,k1c-1m6

    or like this:

    F1:k1e-1m4
    F1:k1e-1m5
    F1:k1e-1m6
    F2:k1c-1m4
    F2:k1c-1m5
    F2:k1c-1m6

    etc, whatever you feel is easier to maintain.

    And you could even use the standard unix tools to do the work for you:

    <?php
    $filename = "postalcodes.txt";
    $postal_code = <whatever you're using to get a postal code>;
    $franchise = system("grep $postal_code $filename | sed 's/:/ /' | awk {'print $1'}");
    ?>

    This way you don't have to monkey around with the code when you add a new franchise or add/change/move a postal code.
     

Share This Page