Jump to content
php.lv forumi

palidziet ar sadalisanu


FT3

Recommended Posts

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 ;/

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

<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 ;)

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...