FT3 Posted October 25, 2010 Report Share Posted October 25, 2010 Kads nevaretu pievienot sadalisanas pa lapam scriptu Mans Kods <?php require("includes/connect.php"); if(isset($_GET['cat'])){ $result=mysql_query("SELECT * FROM movie WHERE category = '".(int)$_GET['cat']."' ORDER by id"); }else{ $result=mysql_query("SELECT * FROM movie ORDER BY id"); } while($row = mysql_fetch_array($result)) { echo "<tr><td><img src='../style/icons/"; echo $row['category']; echo ".gif'></td>"; echo "<td>"; echo $row['title']; echo "</td>"; echo "<td><a href='?go=view-movie&id="; echo $row['id']; echo "'>Просмотор</a></td></tr>"; } ?> mekleju google neko ipašu neesmu atradis ;/ Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 http://php.lv/f/topic/2935-neliels-foruma-temu-apkopojums-no-arhiva-sadalas/ un meklē vārdus "pa lappusēm" Quote Link to comment Share on other sites More sharing options...
FT3 Posted October 25, 2010 Author Report Share Posted October 25, 2010 bet es nezinu ka lai vinus apvienot jo man vel if(isset($_GET['cat'])){ $result=mysql_query("SELECT * FROM movie WHERE category = '".(int)$_GET['cat']."' ORDER by id"); }else{ $result=mysql_query("SELECT * FROM movie ORDER BY id"); } Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 Skaties kā tur ir tas LIMIT izmantots un kabini saviem vaicājumiem galā. Quote Link to comment Share on other sites More sharing options...
FT3 Posted October 25, 2010 Author Report Share Posted October 25, 2010 viss tnx par meklešanas tagiem lieta atrisinata ;DDDDD Quote Link to comment Share on other sites More sharing options...
FT3 Posted October 25, 2010 Author Report Share Posted October 25, 2010 <H2>Список Фильмов</h2> <div id=hcontent> <table width=100%> <?php include 'includes/connect.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = (int)$_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); if(isset($_GET['cat'])){ $sql=mysql_query("SELECT * FROM movie WHERE category = '".(int)$_GET['cat']."' ORDER by id LIMIT $from, $max_results"); }else{ $sql=mysql_query("SELECT * FROM movie ORDER BY id LIMIT $from, $max_results"); } while($row = mysql_fetch_array($sql)){ // Nak visa draza ara tiesi seit. echo "<tr><td><img src='../style/icons/"; echo $row['category']; echo ".gif'></td>"; echo "<td>"; echo $row['title']; echo "</td>"; echo "<td><a href='?go=view-movie&id="; echo $row['id']; echo "'>Просмотор</a></td></tr>"; } if(isset($_GET['cat'])){ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movie WHERE category = '".(int)$_GET['cat']."'"),0); }else{ $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movie"),0); } $total_pages = ceil($total_results / $max_results); echo "<table><tr>"; if(isset($_GET['cat'])){ for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "<td><span class='page_numbers'>$i</span></td>"; } else { echo "<td><a class='page_numbers' href=\"".$_SERVER['PHP_SELF']."?go=movie&cat=".(int)$_GET['cat']."&page=$i\">$i</a></td>"; } } }else{ for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "<td><span class='page_numbers'>$i</span></td>"; } else { echo "<td><a class='page_numbers' href=\"".$_SERVER['PHP_SELF']."?go=movie&page=$i\">$i</a></td>"; } } } echo "</tr></table>"; ?> </table> </div> links irs šads ?go=movie&page=2 bet ja uzliek ?go=movie&page=a vai ?go=movie&page=56456754 uzrada eroru Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\modules\movie.php on line 22 ka lai to izlabot , piem "tada lapa neeksiste !" erora vieta ;) Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 Apstrādā kļūdas! Kaut vai šādi: if(isset($_GET['cat'])){ $sql=mysql_query("SELECT * FROM movie WHERE category = '".(int)$_GET['cat']."' ORDER by id LIMIT $from, $max_results") or die(mysql_error()); }else{ $sql=mysql_query("SELECT * FROM movie ORDER BY id LIMIT $from, $max_results") or die(mysql_error()); } un total_results tev būtu jānoskaidro vēl pirms pašas datu atlases, tad arī varēsi zināt, vai padotais $from nav pārāk liels. vai $max_results = 1 ir ok? $from = (($page * $max_results) - $max_results); // gadījumā, ja $page == 1, tad $from = 1*1-1 = 0; Quote Link to comment Share on other sites More sharing options...
FT3 Posted October 25, 2010 Author Report Share Posted October 25, 2010 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1, 1' at line 1 izvada šo Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 aha - tādēļ, ka nespēj izvadīt mīnus pirmo atgriezto rindu (~; Quote Link to comment Share on other sites More sharing options...
FT3 Posted October 25, 2010 Author Report Share Posted October 25, 2010 neko nesapratu :D Quote Link to comment Share on other sites More sharing options...
Maris-S Posted October 25, 2010 Report Share Posted October 25, 2010 Total iegūšanai šajā gadījumā varētu izmantot MySql funkciju FOUND_ROWS(), nevajadzēs veidot divus vaicājumus. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 found_rows() taču iedos limitētā vaicājuma atgriezto rindu skaitu... Quote Link to comment Share on other sites More sharing options...
Maris-S Posted October 25, 2010 Report Share Posted October 25, 2010 Nē, atgriezīs limitētā vaicājuma rindu skaitu, ja tam netiktu izmantots limit, pēc tā rezultāta uzzinām cik ir lappušu. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 neko nesapratu :D LIMIT -1, 1 nozīmē atgriezt vienu ierakstu sākot ar mīnus pirmo atgriezto. NU NEDRĪKST -1 PADOT! http://dev.mysql.com/doc/refman/5.0/en/select.html The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 25, 2010 Report Share Posted October 25, 2010 Nē, atgriezīs limitētā vaicājuma rindu skaitu, ja tam netiktu izmantots limit, pēc tā rezultāta uzzinām cik ir lappušu. O! Paldies! Nezināju par šo. Un kā tas ietekmē "execution plan"? (nav šobrīd nekā pa rokai kur notestēt) 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.