SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need a $foo replacement for database variables

    One of my tables uses a field named IDParent to identify the parents of the 50 states and provinces. For example, Alaska's parent is the United States, whose IDParent value is usa. Alberta's parent is Canada, can.

    However, there are places where I need two use a two-letter code, rather than three - us, ca. This script takes care of that:

    PHP Code:
    $data_details[IDParent] = substr("$data_details[IDParent]"02); 
    But I need to use the three-letter version farther down the page...but it's stuck on two letters.

    Can someone show me a better way? I THINK what I want I need to do is leave the default setting at three letters (usa, can), then create a special echo statement or value for use in two-letter situations.

    The script below does something like that. It replaces us-ak (Alaska) and ca-bc (British Columbia) with ak and bc...whenever I call up the two-letter versions with $mycode_2Char.

    PHP Code:
    $foo = array("us-""ca-");
    $mycode_2Char str_replace($foo""$mycode); 
    However, this is a little simpler because every page has a unique $mycode value that I can easily plug in. I'm not quite sure how to adapt this script to converting a three letter database value (IDParent) to its first two letters (IDParent2).

    Any tips? Thanks.

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This thread is closed; I figured out a solution. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •