Add css li to php?

2019-09-08 20:07发布

问题:

When I add a <li> element (I want to have all the links in an <ul> centered navigation) to this php pagination script, nothing shows up? But works fine when I use span:

echo "<span class='activestudent_pagination'>$i</span> &nbsp;";

I'm new to PHP and was just wandering if someone could please help me out with what I'm doing wrong?

<div id="pages"><ul>
<?php


$show=6;

echo "<li><a href='?i=p&p=$page'>&#171; PREV</a></li>";

if($page-($show/2) > 1){
$temp=$page-$show;
echo "<li><a href='?p=$temp'>...</a></li>";
}

if($page-($show/2) >= 1 && $page+($show/2) <= $pages){
$start=$page-($show/2);
$stop=$page+($show/2);
}

if($page-($show/2) < 1){
$start=1;
$stop=$show;
}
if($page+($show/2) > $pages){
$start=$pages-$show;
$stop=$pages;
}  


for($i=$start; $i<=$stop; $i++){
if($page==$i){
echo "<li class='activespage'>$i</li>";
}
else{
echo "<li><a href='?p=$i'>$i</a></li>";
}
}

if($page+($show/2) < $pages){
$temp=$page+$show;
echo "<li><a href='?p=$temp'>...</a></li>";
}

echo "<li><a href='?i=n&p=$page'>NEXT &#187;</li></a>";

?>
</ul>

回答1:

You need to close HTML tags in the reverse order you opened them, so

echo "<li><a href='?i=n&p=$page'>NEXT &#187;</li></a>";

should be:

echo "<li><a href='?i=n&p=$page'>NEXT &#187;</a></li>";

That could be the cause of it not displaying right. It's hard to tell without seeing the full HTML output though.



标签: php css class