SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast nosnevel's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with string functions -- find # in a string

    The name filed in a database contains some names that are listed LASTNAME#FIRSTNAME, but they should be listed FIRSTNAME LASTNAME. I have the outline of how to do this, but not the string function expertise to locate the # sign in the string, and then assign the first half to $temp2 and the second half to $temp1:

    Code:
    <?php   //put first name in front of last name
            $database = new Database();
            $dblink = $database->DB_databaseConnect();
    
            $query = "SELECT id, name FROM newsletter";
            $results = $database->DB_executeQuery($query, $dblink);
    
            while ($row=mysql_fetch_array($results)) {
                    // if the name entry has a # mark
                    if ($row['name'] ...   ){        // the the name field contains #           
                            $id = $row['id'];
                            // take everything before the # and call it $temp2
                            
                            // take everything after the # and call it $temp1
                            
                            $name = $temp1." ".$temp2;
                            $query = "UPDATE newsletter SET name='$name' WHERE id='$id'";
                            $results = $database->DB_executeQuery($query, $dblink);
                            }
    ?>
    Thanks in advance for any help with this.
    Larry
    Larry Levenson
    Sigma Web Technologies - Prescott Valley, AZ, USA
    http://www.SigmaWebTechnologies.com

  2. #2
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    list($last$first) = explode("#""LASTNAME#FIRSTNAME");
    $name $first " " $last
    //$name is now 'FIRSTNAME LASTNAME' 

  3. #3
    SitePoint Enthusiast nosnevel's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dangermouse
    PHP Code:
    list($last$first) = explode("#""LASTNAME#FIRSTNAME");
    $name $first " " $last
    //$name is now 'FIRSTNAME LASTNAME' 
    That's WAY too EASY! Thank you!!
    Larry Levenson
    Sigma Web Technologies - Prescott Valley, AZ, USA
    http://www.SigmaWebTechnologies.com


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
  •