duanji4449 2018-02-09 03:08
浏览 49
已采纳

使用for循环将javascript变量插入到json编码的php变量中

I've got several items I'm trying to display within a canvas. I've json my php data to support doing this in javascript.

Now I'm trying to iterate the database names with a for loop so I don't have to write the code for each.

Here's what I've got so far:

for ((var i=2; i<=17; i++) && (var j=3; i<=18; j++)){

if((row.g1c[j]y + row.g1c[j]m != 0) && ((12*row.g1c[j]y + row.g1c[j]m) > (360 + (12*row.O1y + row.O1m)))){

    var g1c[i]w = (360-(12*row.g1c[i]y + row.g1c[i]m)-(12*row.O1y + row.O1m));

} else if (row.g1c[j]y +row.g1c[j]m != 0){

   var g1c[i]w = ((12*row.g1c[j]y + row.g1c[j]m)-(12*row.g1c[i]y + row.g1c[i]m));

} else {}

var g1c[i]x = ((12*row.g1c[i]y + row.g1c[i]m)-(12*row.O1y + row.O1m));
var lineHeight = 15;
var maxWidth = 2.5*(g1c[i]w);
var x = 80+(2.5*(g1c[i]x))+(maxWidth/2);

}

This isn't working and I'm 99.999% sure it has to do with the i and j syntax, but everything I've looked up and tried hasn't worked.

If someone would tell me where my screw-up is, I'd be eternally grateful.

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • duanlu1876 2018-02-12 03:27
    关注

    Decided do go down the PHP route vice Javascript to avoid having to redo my database...

    I'm creating a for loop for each database column and row...

    for ($j=3; $j<=$count; $j++){
        $l = "g1c".$j."m";
        $m = "g1c".$j."y";
    

    I can then use php logic as needed for each row of data that needs to be assessed...

    if(($row[$l] + $row[$m]) != 0){
    .... do something
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图