Redirectionare gresita la link in paginare

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
alexandrutz
Mesaje:8

Redirectionare gresita la link in paginare

imi apare eroare cand dau pe 2,3,etc ma redirectioneaza gresit in browseru

Cod: Selectaţi tot

<?php
//MySQL Database Connect
include 'dbinfo.php'; 

   $tbl_name="images";      //your table name
   $adjacents = 3;       // How many adjacent pages should be shown on each side?
   
   $query = "SELECT COUNT(*) as num FROM $tbl_name";
   $total_pages = mysql_fetch_array(mysql_query($query));
   $total_pages = $total_pages[num];
   
   $seotag = "hot-images";    //for pages seo links, the current one example: "hot-images-1.html"
   $limit = 12;             //how many items to show per page
   $page = $_GET['page'];
   if($page) 
      $start = ($page - 1) * $limit;          
   else
      $start = 0;                        
   
   $sql = "SELECT code FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit";
   $result = mysql_query($sql);
   
   if ($page == 0) $page = 1;               
   $prev = $page - 1;                     
   $next = $page + 1;                     
   $lastpage = ceil($total_pages/$limit);      
   $lpm1 = $lastpage - 1;                  
   

   $pagination = "";
   if($lastpage > 1)
   {   
      $pagination .= "<div class=\"pagination\">";
      //previous button
      if ($page > 1) 
         $pagination.= "<a href=\"$seotag-$prev.html\">&#8592; previous</a>";
      else
         $pagination.= "<span class=\"disabled\">&#8592; previous</span>";   
      
      
      if ($lastpage < 7 + ($adjacents * 2))
      {   
         for ($counter = 1; $counter <= $lastpage; $counter++)
         {
            if ($counter == $page)
               $pagination.= "<span class=\"current\">$counter</span>";
            else
               $pagination.= "<a href=\"$seotag-$counter.html\">$counter</a>";               
         }
      }
      elseif($lastpage > 5 + ($adjacents * 2))   
      {
         if($page < 1 + ($adjacents * 2))      
         {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$seotag-$counter.html\">$counter</a>";               
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$seotag-$lpm1.html\">$lpm1</a>";
            $pagination.= "<a href=\"$seotag-$lastpage.html\">$lastpage</a>";      
         }
         elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
         {
            $pagination.= "<a href=\"$seotag-1.html\">1</a>";
            $pagination.= "<a href=\"$seotag-2.html\">2</a>";
            $pagination.= "...";
            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$seotag-$counter.html\">$counter</a>";               
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$seotag-$lpm1.html\">$lpm1</a>";
            $pagination.= "<a href=\"$seotag-$lastpage.html\">$lastpage</a>";   
         }
         else
         {
            $pagination.= "<a href=\"$seotag-1.html\">1</a>";
            $pagination.= "<a href=\"$seotag-2.html\">2</a>";
            $pagination.= "...";
            for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$seotag-$counter.html\">$counter</a>";            
            }
         }
      }
      
      //next button
      if ($page < $counter - 1) 
         $pagination.= "<a href=\"$seotag-$next.html\">next &#8594;</a>";
      else
         $pagination.= "<span class=\"disabled\">next &#8594;</span>";
      $pagination.= "</div>\n";      
   }
?>
<?php include 'header.php'; ?>        
        <div class="wide_content">

               <h2 class="cf">Hot Gallery</h2>
                <div class="cftext">
                very hot one!
                </div>
                <p class="main_text">
                All the picture are in HD! click on pictures to view full size.
                </p>
                <br />
                <center>
                <a href=http://getiton.com/go/g1140477-ppc?lang=english target="_blank" title="Click here for more."><img src="http://graphics.pop6.com/banners/getiton/english/25868_728x90.jpg" width="728" height="90" border="0" alt="Click here for more." /></a>
                </center>
                <div class="portofolio">
                
                <ul class="item">
   <?php
      while($row = mysql_fetch_array($result))
      {
   
        echo           '<li rel="webdesign">
                        <span class="clip"><img src="images/clip.png" alt="" border="0"/></span>
                  <br />
                        <div class="project_thumb">
                  '.$row["code"].'
                  </div>
                    </li>';
   
      }
   ?>
                </ul>
                
                </div><!-- end of portofolio-->
            
        </div> <!--end of wide content-->
        
    <div class="clear"></div>
    </div> <!--end of main_content-->   
    <center><?=$pagination?></center>

</div><!--end of main_container--> 

<?php include 'footer.php'; ?>
ca sa fii cel mai bun trebuie sa l infrângi pe cel mai bun

MarPlo Mesaje:4343
Salut
In script, numarul paginii e preluat din URL cu: $page = $_GET['page']; , deci, adresa URL din link-uri ar trebui sa contina: .php?page=....
Dar scriptul creaza link-urile de paginare cu ".html" la sfarsit, ceea ce indica faptul ca foloseste un fisier .htaccess care rescrie cu mod-rewrite adresa URL pe server.
De acolo de unde ai luat scriptul ar trebui sa fie ceva si despre codul necesar din .htaccess. Daca nu, trebuie rescrisa partea de creare a link-urilor (asta face cine are nevoie), sau folosesti alt script de paginare. Gasesti pe site la pagina: Scripturi PHP-MySQL.

alexandrutz Mesaje:8
.htacces are

Cod: Selectaţi tot

RewriteEngine On
RewriteRule ^hot-images-([0-9]+)(.*)\.html$ index.php?page=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
- am introdus da eroarea tot aia imi apare.
ca sa fii cel mai bun trebuie sa l infrângi pe cel mai bun

MarPlo Mesaje:4343
Probabil codul din .htaccess e gresit.
Incearca asa:

Cod: Selectaţi tot

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^hot-images-([0-9]+).html$ index.php?page=$1 [NC,L]
- Daca nu merge, nu stiu altfel.

keenbr Mesaje:44
MarPlo scrie:Probabil codul din .htaccess e gresit.
Incearca asa:

Cod: Selectaţi tot

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^hot-images-([0-9]+).html$ index.php?page=$1 [NC,L]
- Daca nu merge, nu stiu altfel.
Nu cred ca ii va merge pentru ca "images" va fi intrepretat ca nextpage, lastpage etc... solutia ar fi urmatoarea:

In htaccess:

Cod: Selectaţi tot

RewriteEngine On
RewriteRule ^hot_images-([0-9]+).html$ index.php?page=$1 [NC,L]
Si in fisier:

Cod: Selectaţi tot

$seotag = "hot_images";

alexandrutz Mesaje:8
nu merge ! o alternativa de paginare pentru continutul de mai sus cum as putea sa fac ?
ca sa fii cel mai bun trebuie sa l infrângi pe cel mai bun

keenbr Mesaje:44
Incearca in fisier:
$seotag = "http://ADresaTa/hot_images

incearca sa pui si site-ul online. daca nu merge, lasa o adresa unde poate fi accesat :)

Subiecte similare