围绕php循环包装div

时间:2012-10-27 13:57:27

标签: php css loops html wrapping

我在尝试围绕创建分页链接的php部分包装HTML Div时遇到了一些麻烦。

我正在围绕代码包装div,但由于某种原因,div出现在分页链接之前(之外)。正如你所看到的,目前所有CSS正在做的是围绕div设置边框。

我无法弄清楚我错过了什么。任何指针都将非常感激。提前谢谢。

PHP / HTML

echo '<div class = "pagination">';

/******  build the pagination links ******/
// range of num links to show
$range = 3;

// if not on page 1, don't show back links

  if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a  href='{$_SERVER['PHP_SELF']}?currentpage=1'><div class = 'pagination_button'> << </div></a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><div class = 'pagination_button'> < </div></a> ";
   }

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " <div class = 'pagination_button_current'><b>$x</b></div> ";
      // if not current page...
      } else {
         // make it a link
         echo " <a  href='{$_SERVER['PHP_SELF']}?currentpage=$x'><div div class = 'pagination_button'>$x</div></a> ";
      } // end else
   } // end if 
} // end for

   if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'><div div class = 'pagination_button'> > </div></a> ";
   // echo forward link for lastpage
   echo " <a  href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'><div div class = 'pagination_button'> >> </div></a> ";
   }
/****** end build pagination links ******/


?>

</div> <!-- End pagination div -->   

CSS

.pagination {
    border:1px solid;
 }  

1 个答案:

答案 0 :(得分:1)

HTML

的语法有一些错误

不要写<<<,更好&lt;&lt;

即使不使用>>>,也不要使用&gt;&gt;

还有一些奇怪的符号,例如<div div class = 'pagination_button'>,它应该是<div class = 'pagination_button'>

至少,只是为了有效性:不要在<div>

中使用<a>