中的两个mysql_fetch_array语句 [英] Two mysql_fetch_array statements in

查看:55
本文介绍了中的两个mysql_fetch_array语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否有任何原因不能在一个while循环中包含对两个不同的mysql查询结果起作用的两个mysql_fetch_array语句?

Is there any reason why I couldn't include two mysql_fetch_array statements working on two different mysql query results in one while loop?

原因是我有一个来自mysql数据库的两个查询结果,每个查询结果包含两列,如下所示:

The reason is I have two query results from a mysql database each containing two columns as follows:

Query 1: Date,     Value 1                 
Query 2: Date,     Value 2

每个查询中的日期始终是以1周为固定间隔的升序的一周结束日期.但是,对于任何一个查询结果,它们可能在不同的日期开始和结束.

Dates in each query are always week ending dates at regular intervals of 1 week ordered in ascending order. However they may start and finish at different dates for either query result.

我想构建数组以返回到日期,值1和值2的调用网页,仅当值1和2在同一时期都可用时.

I want to build arrays to return to the calling web page of date, value 1 and value 2 only where both values 1 and 2 are available over the same period.

我包含了一个if/else块,该块比较每个查询中的第一个日期,并使用mysql_data_seek设置一个指针,该指针的结果集具有最早的开始日期,以确保将其提前到对应于第一个可用日期的日期.另一个记录集.

I have included an if / else block that compares the first date in each query and sets a pointer using mysql_data_seek for which ever result set has the earliest start date to ensure it is advanced to the date corresponding to the first available date in the other record set.

因为最后一个可用日期也可能不同,所以我认为要确保要返回的数组的长度都相同(因此,截断哪个结果中的数据要比另一个结果的最后一个可用日期更近),我以为我可以遍历两个查询结果,如下所示:

Because the last available date may also be different, I thought that to ensure the arrays to be returned are both of the same length (therefore truncating whichever result has the more recent data to the last available date of the other result), I thought that I could iterate through both query results as follows:

$ReturnDate = array();
$ReturnValue1 = array();
$ReturnValue2 = array();

$i=0;
while ($row1=mysql_fetch_array($res_Query1,MYSQL_NUM) && $row2=mysql_fetch_array($res_Query2,MYSQL_NUM)) { 
        $ReturnDate[$i]= $row1[0];
        $ReturnValue1[$i] = (float)$row1[1];
        $ReturnValue2[$i] = (float)$row2[1];
        $i++;
}

但是,第二个返回值数组始终返回零序列.上面的代码有效吗?

However, the second return value array always returns a sequence of zeros. Is the above code valid?

非常感谢

推荐答案

&&更改为and.不,我不是在开玩笑.

Change && to and. No, I'm not kidding.

&&的优先级高于=(但and则不是)

&& has higher priopity then = (but and not) so

$a = foo() && $b = bar()真的是$a = (foo() && ($b = bar()))

这篇关于中的两个mysql_fetch_array语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆