SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use of the Left function

    Hi all

    Im quite new to PHP and Im having a bit of trouble with limiting 'chuncks' of text within a table listing.

    The code lists properties from a database and works perfectly until I want to only choose the first 2 characters of a particular field. the code reads as follows.

    Code:
    while ($properties = mysql_fetch_array($props)) {
      echo "<tr valign='top'>\n";
      $id = $properties['id'];
      $keycode = $properties['StreetName'];
      $housecode = $properties['LEFT(StreetName,2)'];
      $number = $properties['HouseNr'];
      $proptext = htmlspecialchars($properties['StreetName']);
     
      echo "<td>$id</td>\n";
      echo "<td>$number $proptext</td>\n";
      echo "<td>$housecode</td>\n";
      echo "</tr>\n";
    }
    When the page executes I get a blank column. Im sure its just the syntax, but I have tried it all ways putting the ' and the ( charcters in different places.

    The line that will not execute is this one - $housecode = $properties['LEFT(StreetName,2)'];

    Im sure one of you clever people can tell how much of a muppet im being!

    Regards

    Keith

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Ukraine, Khmelnitsky
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $housecode = substr($properties['StreetName'], 0, 2);
    Sergey Bres aka tserbis, Ukraine

  3. #3
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Go to http://us2.php.net/manual/en/function.substr.php for more help on how to manipulate that function.

  4. #4
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.... Thank You.... Thank You....

    You are both Legends! This has been driving me mad all day!

    And thanks also for the refrence site which has been saved to my favorites.

    Regards

    Keith

    A Happy Newbie!


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
  •