I have an ul list with a query and a while loop displaying the li’s inside.
Each li has a border bottom. I need to find a way to make the last li not have a border.
Here is what I am thinking:
<ul>
$z = '0';
$anchors2 = mysql_query("SELECT * FROM anchors WHERE site_url = '$site_current2' AND site_type = 'slave' LIMIT 999 OFFSET 9");
while($anc2 = mysql_fetch_assoc($anchors2)){
$z++;
$s_anchor2 = $anc2['site_anchor'];
$s_current2 = $anc2['site_current'];
if ($z != $total_number_of_rows){ // How can I get the total number of queried rows?
echo '<li><a href="'.$s_current2.'" title="'.$s_anchor2.'" target="_self">'.$s_anchor2.'</a></li>';
} else {
echo '<li style="border-bottom:none"><a href="'.$s_current2.'" title="'.$s_anchor2.'" target="_self">'.$s_anchor2.'</a></li>';
}
}
</ul>
**The problem is I need a way to find out the total number of rows in order to make my code work and remove the border of the last li
Any ideas?
Just tried it with jquery which I new to me. I have several ul lists and here is the code:
function last_li_remove_border() {
$("ul.no_border_last_li li:last").each(function() {
css({border:'none'});
});
}
How can i make it work?
Ty for the answers:)
3 ways:
Use
mysql_num_rows($anchors2)to find out how many rows there are.Use the CSS last-of-type selector
Use jQuery or some other JS library. jQuery would look like:
$("li:last").css({border-bottom:'none'});I’d choose 2, as it means that html is consistent – you shouldn’t be using inline CSS if possible. If not 2, then 1. Using jQuery would be my last resort, by a huge massive margin!