帮助我解决我的时髦 PHP 循环

发布于 2024-10-05 06:29:23 字数 1588 浏览 0 评论 0原文

好的,我有这个 页面 并在 Firefox 中查看正确的结果显示出来了,但是当我在 chrome 或 safari 中查看它时,结果却相差甚远。难道是我正在使用的时髦的 php 循环使它在浏览器中关闭了。这是我的代码,

我正在生成一个左数组和右数组。对我来说

    $left = array();
    $right = array();
$finaltot=0.00;
 for($i=0;$i<count($steps);$i++)
{               
$sql="SELECT *  FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1) ;
$expstep=ExecuteGetRows($sql);


if ($i % 2 == 0) {
      $sql="SELECT SUM(TotalPrice) AS TOT FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1);
      $tots=ExecuteGetRows($sql);
    $left["Step"][$i][]  = $steps[$i];
    $left["expstep"][$i][]  = $expstep;
    $left["final_total"][$i][] = $tots[0]['TOT'];
    $finaltot+=$tots[0]['TOT'];
  } else {    
   $sql="SELECT SUM(TotalPrice) AS TOT FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1);
   $tots=ExecuteGetRows($sql);
    $right["Step"][$i][]  = $steps[$i];
    $right["expstep"][$i][]  = $expstep;
    $left["final_total"][$i][] = $tots[0]['TOT'];
    $finaltot+=$tots[0]['TOT'];

 }

这似乎是一个黑客,因为左数组只有 0,2 ,4,6,8,10 右边有 1,3,5,7,9,11

所以我的循环是这样的

<?php for($i=0;$i<count($left['Step']) * 2;$i++) { ?> 
      <?php $i++; ?>
<?php } ?>

<?php for($i=1;$i<count($right['Step'])* 2;$i++) { ?> 
      <?php $i++; ?>
<?php } ?>

所以正如你所看到的代码有点关闭,我认为这可能是为什么 safari 和 chrome 关闭的问题...任何建议

Ok so i have this page and when viewed in firefox the proper results show up but when i look at it in chrome or safari it is way off. Could it be the funky php loop that i am using that makes it off in the browsers..Here is my code

I am generating a left and right array..seems like a hack to me

    $left = array();
    $right = array();
$finaltot=0.00;
 for($i=0;$i<count($steps);$i++)
{               
$sql="SELECT *  FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1) ;
$expstep=ExecuteGetRows($sql);


if ($i % 2 == 0) {
      $sql="SELECT SUM(TotalPrice) AS TOT FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1);
      $tots=ExecuteGetRows($sql);
    $left["Step"][$i][]  = $steps[$i];
    $left["expstep"][$i][]  = $expstep;
    $left["final_total"][$i][] = $tots[0]['TOT'];
    $finaltot+=$tots[0]['TOT'];
  } else {    
   $sql="SELECT SUM(TotalPrice) AS TOT FROM configure_system WHERE EstimateID='".$_SESSION['ESTQUOTE']."' AND StepID=".($i+1);
   $tots=ExecuteGetRows($sql);
    $right["Step"][$i][]  = $steps[$i];
    $right["expstep"][$i][]  = $expstep;
    $left["final_total"][$i][] = $tots[0]['TOT'];
    $finaltot+=$tots[0]['TOT'];

 }

then since the left array only has 0,2,4,6,8,10
and right has 1,3,5,7,9,11

so my loops are like this

<?php for($i=0;$i<count($left['Step']) * 2;$i++) { ?> 
      <?php $i++; ?>
<?php } ?>

<?php for($i=1;$i<count($right['Step'])* 2;$i++) { ?> 
      <?php $i++; ?>
<?php } ?>

So as you can see the code is a bit off and i think that maybe the problem with why safari and chrome are off...any suggestions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-10-12 06:29:23

为什么不使用 foreach 来代替?

foreach ($right['Step'] as $i => $val) {
     // ...
}

此外,您只需一个查询即可获得相同的结果:

  SELECT SUM(TotalPrice) AS TOT
    FROM configure_system
   WHERE EstimateID='".$_SESSION['ESTQUOTE']."'
GROUP BY StepID

Why do not use foreach instead?

foreach ($right['Step'] as $i => $val) {
     // ...
}

Also you could get the same results with only one query:

  SELECT SUM(TotalPrice) AS TOT
    FROM configure_system
   WHERE EstimateID='".$_SESSION['ESTQUOTE']."'
GROUP BY StepID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文