I have a php script which pulls data from my database and outputs as html, and also adds hyperlinks to the first column of table data.
I would like to change the values for the outputted data for the last column to an abbreviated value,
i.e) JoeBloggs becomes JB
Is this easily done with php?
Below is the current php code:
Code: Select all
// Performing SQL query
$query = "select dvd_titles.dvd_id, dvd_title , round(avg(rating),1) AS rounded_rating , prodn_year , date_format(dvd_rlsdate,'%d %b %y') as rlsdate , dvd_genre, GROUP_CONCAT(CONCAT(critic,'=',rating)order by rating) as criticsratings
from dvd_ratings , dvd_titles , dvd_genres , dvd_critics
where dvd_titles.dvd_id=dvd_ratings.dvd_id AND dvd_genres.dvd_id=dvd_titles.dvd_id AND dvd_critics.critic_id = dvd_ratings.critic_id
group by dvd_ratings.dvd_id
order by dvd_title";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo '<table>';
echo "<tr><th>Title</th><th>Avg.<br>Rating</th><th>Year</th><th>DVD Release Date</th><th>Main Genre</th><th>Critics Ratings</th></tr>"; // Setting Column Names
while( $row=mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo '<tr>',
'<td><a href="detail.php?id=', $row['dvd_id'], '">', htmlentities($row['dvd_title']), '</a></td>',
'<td>', htmlentities($row['rounded_rating']), '</td>',
'<td>', htmlentities($row['prodn_year']), '</td>',
'<td>', htmlentities($row['rlsdate']), '</td>',
'<td>', htmlentities($row['dvd_genre']), '</td>',
'<td>', htmlentities($row['criticsratings']), '</td>',
'</tr>';
}
echo '</table>';