I'm pretty much a newb when it comes to PHP and MYSQL (taught myself, so I make a lot of mistakes :confused: ) So here's the code...
$query = "SELECT DISTINCT(t_tag) FROM tags ORDER BY t_tag desc LIMIT 50";
$results = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
extract($row);
$tag[$x] = $t_tag;
$x++;
}
echo "<table border=1>";
for ($i=1; $i<=$x; $i++) {
$total_tag_usage = mysql_result(mysql_query("SELECT COUNT(t_tag) AS NUM FROM tags WHERE t_tag = '$tag[$i]'"),0);
echo "<tr><td>" .$t_tag[$i]. "</td><td>" .$total_tag_usage. "</td></tr>";
}
echo "</table>";
What I want to accomplish is pull each unique tag from the database (from the tags table, in a column named t_tag), and place the number of times that tag has been used next to it in a table. As of now, the code above looks as if it's spitting out random numbers and it breaks up each tag letter by letter into a cell in the table. For example, if I have the tag "Apple", it's broken up into 5 different cells on the table, one for each letter with the neighboring cell in the same row displaying a random number. I think what I'm trying to do can be done with a single SQL statement, unfortunately, I was unable to write one that works. I figured since this was php code, I should post it in the php forum. Sorry if it should have gone in the SQL forum.