dongshubang7816 2014-01-23 13:59
浏览 57
已采纳

my循环的PHP循环输出缺少一行

Summary of problem: I have a mysql table with some data, I use some phpcode to display the data to an html page, to setup JavaScript variables before a page loads. The loop seems to work fine with one exception, the first row of the table gets dropped or doesnt show. I cant figure out why, is there a small bit of logic Im missing?

I have a mySQL table here: http://gyazo.com/ac75247b1a3f11f59721f03ff9c80d08

and some php code to display it here:

//...

$sql        = "SELECT * FROM ".TABLE_CALCULATOR." WHERE calculation_status = 'A'";
$result     = mysql_query($sql);
$row        = mysql_fetch_array($result);
$num_rows   = mysql_num_rows($result);

if(count($num_rows) > 0 ){
    while ($row = mysql_fetch_assoc($result)) {
        $calculator_data[] = $row;
    }
}else{
    // Send Notication to admin Calculator not set
}

//...

<?php

if(!empty($calculator_data)){
    foreach($calculator_data as $k => $v ){

        if($v['name_value'] == 'perWinPriceMatrix'){

            $per_win_matrinx = explode(",", $v['calculation_values'] );
            $per_win_matrinx_final = array_chunk($per_win_matrinx, 5, true);

            foreach($per_win_matrinx_final as $key => $values ){
                  $var[$key] =  $key.':['.implode(',',$values).']';

            }
            ?> var <?php echo $v['name_value'] ;?> = <?php echo "{".implode(",", $var)."}";?>;<?php echo "
";
        }else{
            ?> var <?php echo $v['name_value'] ;?> = [<?php echo $v['calculation_values'] ;?>];<?php echo "
";
        }
    }
}

?>

this is the output:

 var tax_bronze2 = [30,20,20,5,0];
 var tax_bronze3 = [30,20,20,5,0];
 var tax_bronze4 = [25,20,20,5,0];
 var tax_bronze5 = [25,20,20,5,0];
 var tax_silver1 = [35,30,30,5,0];
 var tax_silver2 = [30,20,20,5,0];
 var tax_silver3 = [30,20,20,5,0];
 var tax_silver4 = [30,20,20,5,0];
 var tax_silver5 = [30,20,20,5,0];
 var tax_gold1 = [70,50,30,10,0];
 var tax_gold2 = [60,40,20,8,0];
 var tax_gold3 = [60,40,20,8,0];
 var tax_gold4 = [60,40,20,8,0];
 var tax_gold5 = [60,40,20,8,0];
 var tax_platinum1 = [100,75,40,10,0];
 var tax_platinum2 = [80,65,40,10,0];
 var tax_platinum3 = [80,65,40,10,0];
 var tax_platinum4 = [80,65,40,10,0];
 var tax_platinum5 = [80,65,40,10,0];
 var tax_diamond1 = [0,0,0,0,0];
 var tax_diamond2 = [120,85,50,20,0];
 var tax_diamond3 = [120,85,50,20,0];
 var tax_diamond4 = [120,85,50,20,0];
 var tax_diamond5 = [120,85,50,20,0];
 var perWinPriceMatrix = {0:[4,4,4,4.5,4.75],1:[5,5.3,5.7,6.2,6.2],2:[7.8,8.6,9.7,10.8,11.8],3:[13,15,17,18,18],4:[19,21,25,30,40]};
 var price_matrix = [19,20,20,20,32,24,24,24,24,42,46,51,53,56,60,60,65,74,79,140,186,214,242,298];
 var provisionalPrice = [60,80,9.25,13,1.3,0.75];

question: Why is output missing a row?

  • 写回答

1条回答 默认 最新

  • dongwei4652 2014-01-23 14:05
    关注

    delete $row = mysql_fetch_array($result); this line fetch row #1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分