Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    separating variables

    Hi all,
    I'm trying to pull a block of 3 to 4 cities from a DB

    but I can't get them separated without having the last city listed having the "|"
    ie. what I get:
    albany | manhattan | long island | buffalo |
    what I want:
    albany | manhattan | long island | buffalo

    what is the function to get this to come out right?
    Thanks for the help
    Ken

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by kred
    what is the function to get this to come out right?
    implode

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Implode is the easyest way. You could also use substr() to remove the chars but it's a way around in most cases.
    Last edited by marek_mar; 09-08-2005 at 09:54 PM.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    I may interpreting your post incorrectly, but I assume you are pulling items out of a db, and displaying them on the page and trying not to have that final bar when you display it. If I am incorrect, ignore this post.

    PHP Code:
    //Untested code: May contain syntactical errors.
    $output "";

    while(
    $row mysql_fetch_assoc($rs))
    {
       
    //Appending to Output the bar and the name of the city
       
    $output .= $row['name'] . " | ";
    }

    //Verifying that there is something in the string.
    if (strlen($output) > 0)
    {
      
    //Removing the Final Bar
      
    $output substr($output0strlen($output) - 3);

    }

    echo 
    $output
    Last edited by CrzySdrs; 09-08-2005 at 11:26 PM.
    Whats the point of a signature?

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks CrzySdrs, that is exactly what I needed.


  •  

    Posting Permissions

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