Hello, I have table for sells, that include: id, user_id, date (linux time) each record in the DB is 1 sell I want to print the user_id of the 10 users who made the top sells (the onces that have the biggest number of row that include the date of this month) how can I do that using PHP and MYSQL?
select user_id from sells where year(date) = (select year(now())) and day(date) = (select day(now())) and month(date) = (select month(now())) order by salescolumn desc limit 10
Maybe you can try this. I didn't test the code but you grab the similar concept even adjust and improve it to your needs. Consult always with php.net/manual as your best advisor. <?php // Make a MySQL Connection first $query = "SELECT user_id, COUNT(user_id) as sold FROM sells GROUP BY user_id"; $result = mysql_query($query) or die(mysql_error()); $sells = array(); while($row = mysql_fetch_array($result)){ $sells[' . $row['user_id'] . '] = $row['sold']; } $ranks = arsort($sells, SORT_NUMERIC); // Sorting from high to low value ?> PHP: