-
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
-
$housecode = substr($properties['StreetName'], 0, 2);
-
Go to http://us2.php.net/manual/en/function.substr.php for more help on how to manipulate that function.
-
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! :D