0

重複の可能性:
クラス X ではない CSS3 セレクターの最後の要素

私はこのループを持っています:

for($t=0; $t<$numRowszzx; $t++)
{
    if(!isset($_GET["prodcat"]))
    {
        header("Location: products.php?prodcat=".$rowzx[0]["category_id"]);
    }
    $categoryName = $rowzx[$t]["category_name"];

    if($rowzx[$t]["category_id"]==$_GET["prodcat"])
    {
        ?>
        <li style="height:30px; line-height:30px; color:#2a598a; font-weight:bold; font-size:14px;"><img src="<?=$site_url?>/images/parrows.png" width="13" height="7" /><span style="padding-left:12px;"><a href="<?=$site_url?>/products.php?prodcat=<?=$rowzx[$t]["category_id"];?>" style=" color:#f15a22; font-weight:bold; font-size:14px;"><?=$categoryName?></a></span></li>
        <?php
    } else {
        ?>
        <li style="<?php if($i > $numRowszzx-1){ ?>margin-bottom:500px;<?php } ?> height:30px;line-height:30px; color:#2a598a; font-weight:bold; font-size:14px;"><img src="<?=$site_url?>/images/parrows.png" width="13" height="7" /><span style="padding-left:12px;"><a href="<?=$site_url?>/products.php?prodcat=<?=$rowzx[$t]["category_id"];?>" style=" color:#2a598a; font-weight:bold; font-size:14px;"><?=$categoryName?></a></span></li>
        <?php
    }
}

今私が必要とするのは、最後のliを取得することです...このコードでは、liが最後の場合、それを与えるために行う必要がありますmargin-bottom:500px;

else {
    ?>
    <li style="<?php if($i > $numRowszzx-1){ ?>margin-bottom:500px;<?php } ?> height:30px;line-height:30px; color:#2a598a; font-weight:bold; font-size:14px;"><img src="<?=$site_url?>/images/parrows.png" width="13" height="7" /><span style="padding-left:12px;"><a href="<?=$site_url?>/products.php?prodcat=<?=$rowzx[$t]["category_id"];?>" style=" color:#2a598a; font-weight:bold; font-size:14px;"><?=$categoryName?></a></span></li>
    <?php
}

何か助けてください。

4

3 に答える 3

1
if($t+1 == $numRowszzx)
{
//this is the last iteration
}
于 2012-10-10T12:44:40.723 に答える
1

elseに条件 $t == ($numRowszzx-1) を使用してif ステートメントを追加できます。

何かのようなもの :

else
{
     if($t == ($numRowszzx-1)) // So we reached the upper bound of your for loop
     {
         // Your <li> here
     }
}

Jimmy が述べたように、else if ステートメントとして書き直すことができます。

于 2012-10-10T12:48:34.567 に答える
0

最後のliが必要な場合はmargin-bottom:500px. そのためには css を使用し、インライン スタイルは使用しないでください。

ノードに追加することで、簡単にスタイルを設定でき:last-childます。

li:last-child {
    margin-bottom:500px;
}
于 2012-10-10T13:10:51.383 に答える