0

I have a foreach which basicaly lists clients withe their username , password and package. now i have a forach running perfect BUT it keeps showing some of the users 3 time for some reason , the data file where its getting all the info does not have the client 3 times. So for some reason foreach echo is showing the same value or user 3 times and then goes on. and its only some users not all. (there are NO duplicates in the data source) pls help :)

Code :

foreach ($info->accountswithinfo->account as $realminfo):

$uncapped=$realminfo->isuncapped;

if ($uncapped=='False')
{
    $username=$realminfo->username; 
    $password=$realminfo->password;
    $packagename=$realminfo->{'package-name'};

    $for=$realminfo->cap;

    $cap=Round(("$for") / (1024 * 1024 * 1024), 2);
}
?>
<tr>
    <?php
    echo '<td class="blockcontentwhite sessionicon">',
         '<td class="blockcontentwhite center">' . ("$username") . '</td>',
         '<td class="blockcontentwhite center">' . ("$password") . '</td>',
         '<td class="blockcontentwhite center">' . ("$cap GB") . '</td>',
         '<td class="blockcontentwhite center">' . ("$packagename") . '</td>';
    endforeach;
    ?>
4

2 回答 2

1

You are displaying the username, password, and other information in every single iteration of the loop. However, you are only changing the username, password, and other information if $uncapped=='False'.

There are cases where $uncapped might be a value other than 'False' which would result in the username, password, and other information not getting set to new values. Your loop would then output the values stored in the previous iteration of the loop (whenever the last time $uncapped=='False').

A possible solution to this issue is to wrap the assigning of values and the output in the same if condition.

于 2013-03-30T05:51:18.743 回答
0

The } bracket ending my if statement should be after my Echo of the values

'<td class="blockcontentwhite center">' . ("$packagename") . '</td>';

} //like this
endforeach;
于 2013-03-30T08:20:50.983 回答