【问题标题】:where to put class or style name在哪里放置类或样式名称
【发布时间】:2025-11-15 16:45:01
【问题描述】:

我想在显示页码的分页底部添加三个类,我在 PHP 中使用了它,但我不知道将类名放在 php echo 中的哪个位置才能工作......因为我得到了错误...

class="box_one" for ... << Prev Page             

class="box_two" for ... echo $thenumrows or $i

class= "box_three"  ... Next Page >>

这里是代码...

 <?php 
         if ($thenumrows != "")
         {
         echo "<br>";
         if ($thecurrentpage > 1)

         echo "<a href='". $_SERVER['PHP_SELF'] . "?cat= ". $theselectedcat ."&rows=  " 
         . $thenumrows ."&page=". $thepreviouspage ."'> 
          << Prev Page </a>&nbsp;&nbsp; "; for ($i=1;$i<=$totalpages;$i++)
         {
         if ($i == $thecurrentpage)
         echo $i ."&nbsp;&nbsp;";
         else
         echo "<a href='". $_SERVER['PHP_SELF'] ."?cat=". $theselectedcat ."&rows=". 
         $thenumrows ."&page=". $i ."'>$i</a>&nbsp;&nbsp;";
         }
         if ($thecurrentpage < $totalpages)
         echo "<a href='". $_SERVER['PHP_SELF'] ."?cat=". $theselectedcat ."&rows=". 
         $thenumrows ."&page=". $thenextpage ."'>Next Page >></a>&nbsp;&nbsp;";
         }
         ?>

请帮忙谢谢。

上午

【问题讨论】:

    标签: php class styles echo


    【解决方案1】:

    我不得不清理你的代码。这些类被添加到a-tags:

    if ($thenumrows != "") {
        echo "<br />";
    
        // Back
        if ($thecurrentpage > 1) {
            echo '<a class="box_one" href="'. $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $thepreviouspage . '"><< Prev Page</a>&nbsp;&nbsp;'; 
        }
    
        // Paginating
        for ($i=1; $i<=$totalpages; $i++) {
            if ($i == $thecurrentpage) {
                echo '<span class="box_two">' . $i .'</span>&nbsp;&nbsp;';
            }
            else {
                echo '<a class="box_two" href="' . $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $i . '">' . $i . '</a>&nbsp;&nbsp;';
            }
        }
    
        // Next
        if ($thecurrentpage < $totalpages) {
            echo '<a class="box_three" href="' . $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $thenextpage .'">Next Page >></a>&nbsp;&nbsp;';
        }
    }
    ?>
    

    【讨论】:

    • 感谢您的帮助,有一个小问题,我几乎不知道为什么会出现问题,当前页面显示的号码可以正常工作,但显示其余号码或预览号码all ($i) like this > 我试图弄清楚为什么会这样显示。在添加课程之前可以正常工作,但不是这个......任何想法......
    • @user3417953 - 已修复。
    • 非常感谢你的作品很棒,我确保我学到了一些东西。再次感谢您的帮助。