I found this code

but when I run it I get several
\n followed by
Count item Name max(ts)
then several a href="/testing.php?sort=max(ts)>"2011-07-08 00:00:00
can you tell me what I am doing wrong?


//connect info

$hostname = "localhost";
$database = "db";
$username = "user";
$password = "password";
$conn = mysql_pconnect($hostname, $username, $password); 
$page = $_SERVER['PHP_SELF']; // Makes $page the current page e.g:query.php

//the query

if (!isset($sort)){
$sort = COUNT(item); // the one to sort by default
mysql_select_db($database, $conn);
$query = "SELECT COUNT(item) Count_of_item, item, name, max(ts) FROM highs WHERE ts > DATE_SUB( now( ) , INTERVAL 30 DAY ) GROUP BY item";
$sql = mysql_query($query, $conn) or die(mysql_error());

//print the table

echo '<table><tr><td>Count_of_item</td><td>item</td><td>Name</td><td>Date</td></tr>';

while($row = mysql_fetch_assoc($sql)){
//echo the results

echo '<tr><td><a href="'.$page.'?sort=COUNT(item)>"'.$row['COUNT(item)'].'</a></td><td><a href="'.$page.'?sort=item>"'.$row['item'].'</a></td><td>a href="'.$page.'?sort=max(ts)>"'.$row['max(ts)'].'</a></td></tr>\n';

//close the table
echo '</table>';