PHP MySQL Data Display Question

message from David B on 17 Jul 2004
I want to display just the first three letters of every word in one
field from a table, and I also want the first letters changed to lower
1) function makeshortcode($name) {
return strtolower(substr($name, 0, 3)) . substr(microtime(), 3, 7);
}
2) $first_three_letters = strtolower(substr("$string", 1));

Below is a copy of my query. Can anyone show where to insert either of
the above scripts or suggest an alternate method of printing out the
first three letters only, all lower case?

Thanks.

<?php
$result = mysql_query('select count(*) from fammammals');
if (($result) && (mysql_result ($result , 0) > 0)) {
} else {
die('Invalid query: ' . mysql_error());
}
$res = mysql_query ("SELECT * FROM fammammals") or die (mysql_error());
echo "<table class='sortable' id='tabedit'>";
//<!-- BeginDynamicTable -->
while ($row = mysql_fetch_array ($res))
{
echo '<tr><td class="text"><'. $_SERVER['PHP_SELF'] .'?id='.
$row['IDMam'] .'>'. $row['FamMamName'] .'</td></tr>'."\n"; }

echo '<tr><td class="text"><'. $_SERVER['PHP_SELF'] .'?id='.
$row['IDArea'] .'>'. $row['NamePA'] .'</td><td class="right">'.
$row['LinkPA'] .'</td></tr>'."\n"; }
*/
echo '</table>';
?>
 
Michael Fesser replied to David B on 19 Jul 2004
.oO(David B)

Do you want to do these modifications when fetching the data (i.e. in
your SQL-query) or after fetching it (i.e. in the PHP-code)?

1) SQL: SELECT ... LOWER(LEFT(yourField, 3)) AS yourField, ...
2) PHP: $value = strtolower(substr($value, 0, 3));

HTH
Micha
 

Archived message: PHP MySQL Data Display Question (Macromedia Dreamweaver Web Design)