多次运行 while($row = sqlsrv_fetch_array($result)) [英] Running while($row = sqlsrv_fetch_array($result)) multiple times

查看:31
本文介绍了多次运行 while($row = sqlsrv_fetch_array($result))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 MSSQL 数据库中检索几个表,然后运行这些表以从中获取订单信息.

I am retrieving a couple of tables from a MSSQL database, which I am then running through to obtain order information from.

我的代码如下所示:

    while($row = sqlsrv_fetch_array($orderResult))
    {
        ......code........
        ..................
        while($statusRow = sqlsrv_fetch_array($statusResult))
        {
            ....code....
        }
        ....code....
    }

现在我的问题是,在第二个循环运行后,它再也不会运行了.每次第一个循环运行时我都需要它运行.

Now my problem is that after the second loop runs through, it never runs again. And I need it to run every time the first loop runs.

我可以做些什么来重置第二个循环以再次运行?

Is there anything I can do to reset that second loop to run again?

先谢谢你.任何帮助或朝着正确方向的推动都会非常有帮助.

Thank you in advance. Any help or a push in the right direction will be very helpful.

推荐答案

阅读 sqlsrv_fetch_array()

你可以做这样的事情来重置

You can do something like this to reset

// reset, and get first row
$row = sqlsrv_fetch_row($result, SQLSRV_FETCH_BOTH, SQLSRV_SCROLL_FIRST);

// get second (and nth row) normally
$row = sqlsrv_fetch_row($result);

或者,我认为您可以通过在查询中执行 JOIN 以返回单个结果而受益.像这样手动合并结果似乎有点骇人听闻.

Alternatively, I think you could benefit from doing a JOIN in your query to return a single result. Merging results manually like this seems a little hackish.

这篇关于多次运行 while($row = sqlsrv_fetch_array($result))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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