ArnisR Posted October 29, 2010 Report Share Posted October 29, 2010 Tātad uz servera ir direktorija, kas satur daudzus attēlus. Ar PHP visi attēli tiek nolasīti pa tiešo no tās mapītes un izvadīti. Tad kā varētu sadalīt attēlus pa lappusēm, ja tie sakrājas lielā daudzumā? Ir kādas idejas? Quote Link to comment Share on other sites More sharing options...
reiniger Posted October 29, 2010 Report Share Posted October 29, 2010 Variants ir tads ka saskaiti cik attēli ir šajā mape tad ar ciklu vai ar masīvu attēlot tik bildes cik vēlies. Vari iemest bilžu attēlošanas kodu lai var tev palīdzēt precīzāk tavā situācijā. Quote Link to comment Share on other sites More sharing options...
ArnisR Posted October 29, 2010 Author Report Share Posted October 29, 2010 (edited) Bildes tiek attēlotas šādi: <?php if ($handle = opendir('img/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { printf('<img class="picture" src="img/%s" alt="img"/>', $file); } } closedir($handle); } ?> Edited October 29, 2010 by ArnisR Quote Link to comment Share on other sites More sharing options...
Val Posted October 29, 2010 Report Share Posted October 29, 2010 Vienkāršāk būtu failu nosaukumus pieglabāt datubāzē un tad no tās jau lasīt tikai vajadzīgos nosaukumus atkarīgā no lappuses numura. Quote Link to comment Share on other sites More sharing options...
waplet Posted October 29, 2010 Report Share Posted October 29, 2010 vienkāršāk būtu ielasīt masīvā un tad masīvu parādīt lapaspusēs.. piemērs: <?php $avgal[$gallery] = isset($gallery) ? $avgal[$gallery] : $avgal[1]; $path = "subpages/galerija/{$avgal[$gallery]}/"; $pictures = glob($path."images/*.jpg"); $p = $p = isset($_GET['p'])? (((int)$_GET['p'] == 0) ? 1 : (int)$_GET['p']) : 1; $perpage = 25; $start = ($p-1)*$perpage; $end = $start+$perpage; ?> <div id="gallery"> <div class="galleryrow"> <? $pics = array_slice($pictures,($p-1)*$perpage,$perpage); $i = 1; foreach($pics as $pic){ print '<div class="gallerydata"> <table> <tr valign="middle"> <td> <a href="'.$pic.'" rel="lightbox"><img src="'.cropmaker($pic, 80, 0.2, $avgal[$gallery]).'"/> </a> </td> </tr> </table> </div>'; if($i % 5 == 0){ print '</div><div class="galleryrow">';} $i++; } ?> </div> <? echo drawpages(count($pictures), $perpage,"page=portfolio&gallery=".htmlspecialchars($gallery));?> </div> draw pages no defektologs.lv nedaudz pielabots no manis. function drawpages($count, $perpage, $lapa, $offset = 5){ $pages = ceil($count/$perpage); if($pages < 2) return ''; $r = '<ul class="pages" style="clear:left;">'; $page = (empty($_GET['p']) || $_GET['p'] < 2) ? 1 : (int)$_GET['p']; $first = $page >= $offset+1 ? $page-$offset : 1; $last = $page <= $pages-$offset ? $page+$offset : $pages; if($page > 1) $r.= sprintf('<li><a href="?%s&p=1">«</a></li><li><a href="?%s&p=%d"><</a></li>',$lapa, $lapa, $page-1); for($i = $first; $i <= $last; $i++) $r.= sprintf('<li%s><a href="?%s&p=%d">%d</a></li>', $page==$i ? ' class="active"' : '', $lapa, $i, $i); if($page < $pages) $r.= sprintf('<li><a href="?%s&p=%d">></a></li><li><a href="?%s&p=%d">»</a></li>', $lapa, $page+1, $lapa, $pages); $r.= '</ul>'; return $r; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.