Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:14:19+00:00 2026-06-15T13:14:19+00:00

I have a problem with the following blocks of code. I cannot have them

  • 0

I have a problem with the following blocks of code. I cannot have them both in the same page, or the last one fails (doesn’t matter if they change place, the last one fails). If I comment out one (regardless of which) then the other one works. So it doesn’t look like an issue with the actual code perhaps?

Is it not possible to run these two in the same page? I am obviously doing something wrong, so please help me point out what it is.

while( $test = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
    if ($_GET['unit'] == '15min') { $newDate = $test['dt']->format('H:i:s'); }
    if ($_GET['unit'] == 'hour') { $newDate = $test['dt']->format('m/d H:i'); }
    if ($_GET['unit'] == 'day') { $newDate = $test['dt']->format('Y/m/d'); }
    $dates[] = $newDate;
    $values[] = $test[$pick_graph];
}

and the second one

while( $row = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) {
$newDate = $row['dt']->format('Y/m/d_H:i:s');

    echo    '<tr>'.
            '<td>'.$row['net']."</td>".
            '</tr>';
}

There’s no error message or anything. When the second loop runs, it’s as if $data is empty or something as it doesn’t loop through anything, putting an echo in there doesn’t output anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:14:20+00:00Added an answer on June 15, 2026 at 1:14 pm

    Like a lot of patterns in computer science, such as file IO, the results from a query in most libraries is treated as a stream. You get get the results as they come, but you can’t skip backwards and you can’t start over without rerunning the query.

    You can either run the query again, or cache the results in an array.

    $cache = array();
    while ($row = sqlsrv_fetch_array($data, SQLSRV_FETCH_ASSOC))
        $cache[] = $row;
    

    Then you can foreach over the $cache in your two locations doing the same logic as you do in your question.

    Caching is the better option in most cases.

    However, if you’re talking about a really large result set (1000s), you’re may be better off running the query twice since you only need to store in RAM one row at a time. Rows that have already been used will be garbage collected.

    As in all performance things, if it matters that much, profile it both ways and determine which meets your objectives.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Never thought I'd have this problem :) The following snippet of code works in
i'm new to jquery .I have problem in the following code .I saved it
I have a JSF2 application and a page with the following code: <h:inputText id=someInput
In the Page TSConfig on the root page I have the following code: /////////////////////////////////////////////////////////////
I have a problem following from my previous problem . I also have the
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I
Hi i have following Problem. I write a Mediawiki Extension where i need some
I have a problem with following script. It generates a list of places which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.