When you are using wpdb it is already doing the sorting and putting it into array for you so you don't need mysql_fetch_assoc - also you should use wpdb prepare to sanitize the strings, especially when using $_GET as you are vulnerable to sql injection otherwise - revised code: