barons Posted March 16, 2005 Report Share Posted March 16, 2005 ir shaads kods: $page = $_GET['page']; if ($page == "") { $page = 1; } $fwd = $page - 1; $rwd = $page +1; $perpage = 5; $filename = "lapas.php"; $fd = fopen ("java/action/action.txt", "r"); while (!feof ($fd)) { $buffer = fgets($fd, 4096); $lines[] = $buffer; } fclose ($fd); $result = count($lines); $count = $result-1; if ($count == 0) { $totalpages = 0; } else { $totalpages = intval(($count - 1) / $perpage) + 1; } $page = $totalpages - ($page - 1); $end = $count - (($totalpages - $page) * $perpage); $start = $end - ($perpage - 1); if ($start < 1) { $start = 1; } if ($start < 0) { $start = 0; } for ($i = $end; $i>=($start-1); $i--) { $tmp = explode(":",$lines[$i]); print("<br>$tmp[1]<br>"); $count++; } echo "<center>"; if ($fwd > 0 && $rwd > 0 && $rwd<$totalpages+1) { echo "<br><a href=\"$filename?page=$fwd\"><<</a>"; echo "<a href=\"$filename?page=$rwd\">>></a><br>"; } else if ($fwd == 0) { echo "<a href=\"$filename?page=$rwd\">>></a><br>"; } else if ($rwd == 0) { echo "<br><a href=\"$filename?page=$fwd\"><<</a>"; } else if ($rwd == $totalpages+1) { echo "<a href=\"$filename?page=$fwd\"><<</a><br>"; } for ($i = 1; $i<=$totalpages; $i++) { echo " [<a href=\"$filename?page=$i\">$i</a>] "; } echo "</center>"; bet vish man raada pirmaa lapa rindas 10,9,8,7,6,5 naakamaa lapa 5,4,3,2,1 bet man vajag 10,9,8,7,6 naakamaa lapaa 5,4,3,2,1 Kur kljuuda? <_< Link to comment Share on other sites More sharing options...
Delfins Posted March 16, 2005 Report Share Posted March 16, 2005 vai tiešam tu pats neredzi ? 10,9,8,7,6,5 = 6 elementi, bet tev vajag 5... nepareizi $start tiek aprēķināts PS: drausmīgs kods.. protams nav brīnums ka pats neko nevari atrast... (un droši vien arī citi :)) Link to comment Share on other sites More sharing options...
Delfins Posted March 16, 2005 Report Share Posted March 16, 2005 diff: -- for ($i = $end; $i>=($start-1); $i--) ++ for ($i = $end; $i>=$start; $i--) Link to comment Share on other sites More sharing options...
barons Posted March 16, 2005 Author Report Share Posted March 16, 2005 diff: -- for ($i = $end; $i>=($start-1); $i--) ++ for ($i = $end; $i>=$start; $i--) 15077[/snapback] Jaa izdodas, bet tikai pirmais ieraksts jaatstaa tuksh! Link to comment Share on other sites More sharing options...
v3rb0 Posted March 16, 2005 Report Share Posted March 16, 2005 iesaku jau no sākuma radināties ka nevajag jaukt tagus ar php kodu vienā maisā kopā - nu acis var izmezgīt un pavisam nemaz negribās pat skatīties kur ir kļūda :rolleyes: Link to comment Share on other sites More sharing options...
рпр Posted March 16, 2005 Report Share Posted March 16, 2005 iesaku jau no sākuma radināties ka nevajag jaukt tagus ar php kodu vienā maisā kopā - nu acis var izmezgīt un pavisam nemaz negribās pat skatīties kur ir kļūda :rolleyes: 15081[/snapback] nu tad pasaki kā būtu pareizāk. ar substitūcijām? Link to comment Share on other sites More sharing options...
v3rb0 Posted March 16, 2005 Report Share Posted March 16, 2005 nu tad pasaki kā būtu pareizāk. ar substitūcijām? 15082[/snapback] ai, laikam parāvu fleimu, bet es stāstu pa labi un pa kreisi ka vajag pieturēties pie MVC modelis - datu source + minimāli php, controlieris php un templeiti kā view layeris. protams, ja scripts beidzas ar prev/next pogām, tad ir vienalga kā dara un raksta. Link to comment Share on other sites More sharing options...
Recommended Posts