php - MySQL all select rows in range -


i need retrieving data rows in range. let's table:

enter image description here

that's need:

i need sort rows id , 9 rows, gameid 1 , winner's unique_id must in middle. example:

$gameid = 1; $winner = "iii"; 

so should return:

5.eee 6.fff 7.ggg 8.hhh 9.iii <--- winner in middle 10.jjj 11.kkk 12.lll 13.mmm 

how can achieve result?

thanks.

edit:

$b = $db->query("select * test gameid = 1 , unique_id = 'iii'"); $res = $b->fetch(); $winnerid = $res['id']; $b2 = $db->query("select * test id between $winnerid-4 , $winnerid+4 order id asc"); $data = $b2->fetchall(); 

this works, wondering if it's possible in single row.

is you're looking for?

it first finds id of winner, selects rows ids smaller , greater 4. (4 + 4 + 1 = 9)

select *  rows  id between      (select @id := id rows unique_id = "iii") - 4 , @id + 4 

example


Comments