There is no ranking functionality in MySQL. The closest you can get is to use a variable:
SELECT t.*,
@rownum := @rownum + 1 AS rank
FROM YOUR_TABLE t,
(SELECT @rownum := 0) r
so how would that work in my case? I'd need two variables, one for each of col1 and col2? Col2 would need resetting somehow when col1 changed..?
Yes. If it were Oracle, you could use the LEAD function to peak at the next value. Thankfully, Quassnoi covers the logic for what you need to implement in MySQL.
How to pass an array within a query string?
Insert new item in array on any position in PHP
How to check whether an array is empty using PHP?
Converting an integer to a string in PHP
How can I add elements to an empty array in PHP?
How to find the foreach index?
How can I capture the result of var_dump to a string?
Create a folder if it doesn't already exist