php - Mysql select list of items (repeat until certain amount) -


i have following structure:

table: products  id, name, sort_order 

let's have 5 products, want 20.

how loop through 20 results?

additionally, i'll need start @ specific sort_order. let's have

1,2,3,4,5 

and want 20 results , start @ 3. should end as:

3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,etc. 

any ideas? i'm totally lost.. thank you!

$how_many = 20; $counter = 0; $rows = array();  $result = mysql_query("your query"); while($row == mysql_fetch_row($result)) {   $rows[] = $row; }  $expanded = array(); for($i = 0; $counter < $how_many; $counter++) {   $expanded[] = $rows[$i];   $i++;   if($i == count($rows)) {     $i = 0;   } } 

and $expanded filled 5 rows 4 times.

edit: , don't forget adjust $i start element. example mean $i = 2 (third element).


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -