0

I found this code
http://www.daniweb.com/web-development/php/code/301902

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?

<?PHP

//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>';
?>

Thanks,
Scott

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Rogueit
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.