0

我正在制作一个机会表格,我在 wordpress 中提供了更新和删除功能。我的问题是这个 for 循环有什么问题.. 我得到了错误的 i 值。如果我删除任何一个机会,它将无法打印“$opportunity_exp_date[$i]”。你们可能很难理解,但这是我的问题。这是我的代码。

for($i=count($contact_opportunity);$i>=0;$i--){  //for listing of Won opportunities
    if($contact_opportunity[$i]!='0' && !empty($contact_opportunity[$i])){ ?>
    <?php if($opportunity_status[$i]=='Won'){?> 
        <div class="won-opp"><h3>Won</h3></div>              
        <?php echo "<div class='oname'>"."New Opportunity '".$contact_opportunity[$i]."' added"."</div>"; ?>
        <a href="<?php echo admin_url( "admin.php?page=contact_profile&post=$pid&opnm=$contact_opportunity[$i]&opamt=$opportunity_amount[$i]&opedt=$opportunity_exp_date[$i]&opsts=$opportunity_status[$i]&opnt=$opportunity_note[$i]" )?>"><span class="opp-edit" title="edit"></span></a> 
        <span class="btn_remove_opp" title="delete opportunity"></span>             
        <input type="hidden" value="<?php echo $contact_opportunity[$i]?>" class="del_op_nm">
        <input type="hidden" value="<?php echo $opportunity_status[$i]?>" class="del_op_sts">
        <input type="hidden" value="<?php echo $opportunity_exp_date[$i]?>" class="del_op_exp">
        <input type="hidden" value="<?php echo $opportunity_amount[$i]?>" class="del_op_amt">
        <input type="hidden" value="<?php echo $opportunity_note[$i]?>" class="del_op_nt">
        <div id="opp-list">
        <?php                       
            echo "<span class='sts'>".$opportunity_status[$i]."</span>"." Expected close on ".$opportunity_exp_date[$i]."<br>";
            echo $opportunity_amount[$i]." "."<div class='footer-op-nt'>".$opportunity_note[$i]."</div>"."<br>";
        ?>                                                              
        </div>
        <br>
    <?php }
    }
}
4

1 回答 1

0

我相信你已经落后了;不要在循环中使用 count() 它会更慢 xD

$count= count($contact_opportunity);
for($i=$count-1;$i>=0;--$i){ //for listing of Won opportunities
于 2013-05-14T13:29:46.863 回答