$max_rows) $to = $max_rows - $from; # use mysql's "limit from,to" to select the correct rows $query = "select imagepath,title,description from pagination_images order by " . $order . " limit " . $from . "," . $to; $result = mysql_query($query) or show_error("Query failed: " . mysql_error()); $numrows=mysql_num_rows($result); # if id is lastpageid substract "rest" (= npages on last block) to get startid $max_id = ceil($max_rows / $nrows); if ($id == $max_id ) { if ($id%$npages == 0) { $rest = $npages; } else { $rest = $id%$npages; } $startid = $id - $rest + 1; } else { $startid = $id; } if ($numrows > 0) { # create table with id = "media" echo "\n"; echo ""; echo ""; echo '' . "\n"; echo '' . "\n"; echo "\n"; $count=0; # a little magic to start showing the correct pages # the idea is to determine the start (and end, but that's just the end of the while-loop) # of the current pagination, determined by $id # for example: if our id = 3 and we show 10 pages per block the pages are from 1 - 10 # if our id = 21 and we show 10 pages per block the pages are from 21 - 30 # if our id = 20 and we show 10 pages per block the pages are from 11- 20 $pagecount = $id - ($id%$npages - 1); if ($id%$npages == 0) $pagecount = $pagecount - $npages; # lower pagecount because a bit further we do a "pagecount++" before using it. $pagecount -= 1; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($count%$nrows == 0) { $pagecount++; if ($pagecount == $id) { # this tbody (page) will be visible echo "\n"; } else { # these tbody's (pages) are hidden echo "\n"; } } # data for tbodyX # make even/odd rows a different color if ($count%2 == 0) { echo ""; } else { echo ""; } echo ""; echo ""; echo ""; echo "\n"; $count++; } echo "
ImageTitleDescription
" . addslashes($line[" . $line['title'] . "" . $line['description'] . "
\n"; } } # -------------------------------------------------------------------- # main # -------------------------------------------------------------------- $sort = form_var('sort'); $id = form_var('id'); $npages = form_var('npages'); $nrows = form_var('nrows'); $max_rows = form_var('max_rows'); $from = form_var('from'); $to = form_var('to'); show_table($sort,$id,$npages,$nrows,$max_rows,$from,$to); ?>