doushi1473 2013-11-06 18:13
浏览 7

Foreach有2 $ i

I'm trying to run 4 identical queries with different numbers, like so:

for($i=0;$i<5;$i++)
{
    $sql[$i] = "SELECT * FROM whatever";
    $sql[$i.$i] = "SELECT * FROM whatever2";
    $res[$i] = mysql_query($sql[$i]);
    $res[$i.$i] = mysql_query($sql[$i.$i];

    while ($row[$i] = mysql_fetch_array($res[$i]))
    {
        $val[$i] = $row[$i]['Col1'];
    }

    while ($row[$i.$i] = mysql_fetch_array($res[$i.$i]))
    {
        $val[$i.$i] = $row[$i.$i]['Col2'];
    }
}

However, it doesn't work. If i include echo $val[$i.$i] in that for it echoes nothing. So I guess my real question is how would I overcome this? I need to run that query 4 times, where $i=1 to $i = 4, so I get $val1, $val2, $val3, $val4. Why can't I declare values with $row[$i.$i]?

PS I know I shouldn't use SQL, I was hired to fix stuff =)

  • 写回答

1条回答 默认 最新

  • doqdcks3948 2013-11-06 18:16
    关注

    That's just wrong. Why don't you use $sql1[$i] and $sql2[$i] ? If you go to 11 $i.$i when i = 1 and $i when i = 11 will collide.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图