-4
foreach($CarAdList as $CarAd)
{
    echo($msg .= '<tr><td>'.$CarAd->getCarAdID().'</td><td>' .$CarAd->getBrandText().'</td><td>' .$CarAd->getDescription(). '</td><td><a href="status.php?id='.$CarAd->getCarAdID().'"><img src="../images/active.png" /></a></td><td><img src="../images/delete.png" width="30px" /></td></tr>');
}

e.g, the number of rows =38

n= the number of rows * the number of rows--

it is running n times

so its displaying

5
5
4
5
4
3
5
4
3
2
5
4
3
2
1
4

2 に答える 2

1

The loop only runs the requested amount of times, but your output does not match. That is because you're adding text to $msg and at the same time echo it.

Either construct $msg in the loop and echo it later, or echo without concatting the previous result, like so:

foreach($CarAdList as $CarAd)
{
    echo '<tr><td>'.$CarAd->getCarAdID().'</td><td>' .$CarAd->getBrandText().'</td><td>' .$CarAd->getDescription(). '</td><td><a href="status.php?id='.$CarAd->getCarAdID().'"><img src="../images/active.png" /></a></td><td><img src="../images/delete.png" width="30px" /></td></tr>';
}
于 2012-09-23T21:38:29.457 に答える
1

echo($msg .= 'somecontent') is a pretty strange construct. Either you want to concat the value and output it in the end, or you do the output immediately.

foreach($a as $b) {
   echo $b;
}

or

$var = '';
foreach($a as $b) {
   $var .= $b;
}
echo $var
于 2012-09-23T21:39:57.467 に答える