Splitting up a string of values
Posted: Sun Jan 28, 2007 3:41 pm
I have a script which retreives data from my database then output the results as html. However the final field (criticsratings) consists of a string of values 1,2,3,4,5,6,7 is it possible to use php to split these values up into seperate fields?
Below is the current php code:
Below is the current php code:
Code: Select all
// Performing SQL query
$query = "select dvd_title, round(avg(rating),1) AS rounded_rating, prodn_year, date_format(dvd_rlsdate,'%d %b %y'), dvd_genre, director, GROUP_CONCAT(rating ORDER BY critic_id)
from dvd_ratings, dvd_titles, dvd_genres, directors
where dvd_titles.dvd_id=dvd_ratings.dvd_id AND dvd_genres.dvd_id=dvd_titles.dvd_id AND directors.dvd_id=dvd_titles.dvd_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<></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>';