Grouping result by 3 each

hi am trying to group result by 3, am not talking about the normal group by but something like this

1 a
2 a
3 b
4 c
5 a
6 b
7 a
8 a
9 c
10 c
11 b
12 b

it should be

1 a
2 a
5 a
3 b
6 b
11 b
4 c
9 c
10 c

hope u understand

this my code below

$query = "SELECT a.*, ca.cat_name, ca.cat_id, ca.cat_image, s.team_id, s.team_image AS teamsimg1, s.teams AS teams1, ss.team_id, ss.team_image AS teamsimg2, ss.teams AS teams2 from " . $DBPrefix . "auctions a
            LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = a.team1)
            LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
            LEFT JOIN " . $DBPrefix . "categories ca ON (ca.cat_id = a.category)
        WHERE closed = 0 AND suspended = 0 AND starts <= :time
        AND featured = 1
        AND soccermatch = 1
        AND category != '199'
        AND category != '200'
        ORDER BY starts DESC
            LIMIT 20

thansk alot

Looks completely random to me …

To me it looks as if it’s ordered first by the second column, then by the first column, but with the number of similar results in the second column limited to three*. I’ve no idea how that could be done in a single query (not least because the query shown has far more columns and I don’t know which is which), but it would be easy to do the ordering in the query, and then just have the PHP do the stripping of fourth and subsequent instances of the second column value.

( * - unless the required sequence continues after the sample given).

1 Like

hi not sure what u talking about u mean like a subquery

random in wat sense

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.