PHP code to display Address

Discussion in 'PHP' started by Omzy, Nov 15, 2008.

  1. #1
    Currently I have a string variable as follows:

    
    $address=$address1.", ".$address2.", ".$district.", ".$town.", ".$county.", ".$postcode;
    
    Code (markup):
    And I have a JavaScript Tooltip that displays $address onClick:

    
    echo ' <a href="#" onclick="Tip(\''.$address.'\'); return false" ';
    
    Code (markup):
    This works fine, but there is one problem - sometimes a client's address does not have a district, and as a result an extra comma gets displayed.

    Now I did create a function with some IF statements in to check what data is there and what isn't but I had trouble making a call to this function within the onClick JavaScript function. What is the best way of going about this?
     
    Omzy, Nov 15, 2008 IP
  2. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I just realised I cant use a function as it cant get declared more than once...
    Is there any way I can include IF statements in my $address variable?
     
    Omzy, Nov 15, 2008 IP
  3. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    It seems that you are quite up to scratch with PHP.

    I would suggest, doing a str_replace() on whereever the string ", ," is and replacing it with ",".
    This is the most simple solution I can suggest.
     
    arnek, Nov 15, 2008 IP
  4. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Cheers arnek, that has worked great.
     
    Omzy, Nov 15, 2008 IP
  5. cipals15

    cipals15 Well-Known Member

    Messages:
    1,085
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    100
    #5
    $_POST['input_name'] <-- Use this in your if statements at the php source code.
     
    cipals15, Nov 15, 2008 IP
  6. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ^ How does that work?
     
    Omzy, Nov 15, 2008 IP
  7. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here u go

    
    $district = (empty($district)) ? '' : $district.", ";
    $address=$address1.", ".$address2.",".$district.$town.", ".$county.", ".$postcode;
    
    Code (markup):
     
    atlantaazfinest, Nov 15, 2008 IP