帮助我解决我的时髦 PHP 循环
好的,我有这个 页面 并在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用 foreach 来代替?
此外,您只需一个查询即可获得相同的结果:
Why do not use foreach instead?
Also you could get the same results with only one query: