I am making a review system and I need to be able to only select the DISTINCT url from the database, but then pull the relevant page title and rating time. I have managed to get it working by using:
<?php
//opens conection
include 'conn.php';
echo $_COOKIE["search"];
$sql = "SELECT * FROM feedback WHERE url LIKE '%$_COOKIE[search]%' GROUP BY url ORDER BY ratingtime DESC";
//runs the query
$query = mysql_query($sql);
$linecount = 1;
//populates the table with the information
echo '<table id="myTable" class="tablesorter">';
echo'<thead>
<tr class ="null">
<th>URL</th>
<th>Page Title</th>
<th>Date Last Modified</th>
<th>Average Rating</th>
</tr>
</thead>';
echo '<tbody>';
echo '<tr>';
while($row = mysql_fetch_array($query))
{
echo '<td class="overFlow"><a href="extra_info.php?url='.$row['url'].'">' .$row['url']. '</a></td>';
echo '<td><a href="extra_info.php?url='.$row['url'].'">' . $row['pagetitle'] . '</a></td>';
echo '<td>' . $row['ratingtime'] . '</td>';
$check = mysql_query("SELECT `rating` FROM feedback WHERE url = '$row[url]'");
$totalvotes = mysql_num_rows($check);
$result = mysql_query("SELECT SUM(rating) AS 'rating_total' FROM feedback WHERE url = '$row[url]'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$add = $row['rating_total'];
$average = $add / $totalvotes;
echo '<td>' .round($average, 2). '</td>';
echo '</tr>';
$linecount++;
}
echo '</tbody>';
echo "</table>";
?>
I just wondered if there was a much better way to go about doing this? I am a complete noob when it come to php so if you provide any advice could you please provide evidence/documentation so that I can read up on it and learn.