I know I am probably making this more difficult than it needs to be, but I can't figure out how to pick out the top 10 most occurring entries from a MySQL table and put them into an HTML table using PHP.
Keep in mind I'm new to MySQL and PHP, and I'm not all that familiar with anything except the basics (simple SQL queries, loops, and variable storage).
On to the problem...
The MySQL table consists of a record number (pk), a record, and the user ID of the person who entered it.
There are multiple records in the table that are the same. I am trying to find out what the top 10 most entered records are, and display the top 10 of all records entered, and the top 10 of an individual user.
A couple ideas I had were:
1)
Using mysql_num_rows to find out how many rows there were of record X.
It would be something like this:
The main problems I have with this method are how to code it so $n is incremented, but the search stops running when you get to the last record, and how to store the data so I can refer back to it and pick out the top 10.
2)
Take the record of row 1 and compare it to the record in row 2. If they match then add a tally. Store the tallies and records (in an array?) and pull out the top 10.
Any ideas or help would be greatly appreciated.
Like I said, I am new to MySQL and PHP, so feel free to assume I don't know anything.
Thanks!
Keep in mind I'm new to MySQL and PHP, and I'm not all that familiar with anything except the basics (simple SQL queries, loops, and variable storage).
On to the problem...
The MySQL table consists of a record number (pk), a record, and the user ID of the person who entered it.
There are multiple records in the table that are the same. I am trying to find out what the top 10 most entered records are, and display the top 10 of all records entered, and the top 10 of an individual user.
A couple ideas I had were:
1)
Using mysql_num_rows to find out how many rows there were of record X.
It would be something like this:
Then store the record, and the number in an array(?) where I can refer back to it, and pick out the top 10.query1: select record from table where record_num = $n; <- ($n would need to be incremented somehow)
$record = (the returned record);
query2: select record from table where record = $record;
$num_rows = (number of rows returned);
The main problems I have with this method are how to code it so $n is incremented, but the search stops running when you get to the last record, and how to store the data so I can refer back to it and pick out the top 10.
2)
Take the record of row 1 and compare it to the record in row 2. If they match then add a tally. Store the tallies and records (in an array?) and pull out the top 10.
Any ideas or help would be greatly appreciated.
Like I said, I am new to MySQL and PHP, so feel free to assume I don't know anything.
Thanks!