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 6007855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:44:31+00:00 2026-05-23T01:44:31+00:00

I have to run a pairing algorithm for a game and when the pairing

  • 0

I have to run a pairing algorithm for a game and when the pairing is done, I display the pairing on HTML and create a csv file as well. Right now, once I am done with pairing, I create a multidimensional array to store the specific value and then pass it to the function in same php file to generate the csv file. However, doing this outputs the entire page code i.e. html and php code to the .csv file. Here is the code:

   function performPairing()
   {
       .... 
      $count=0;
      $resultArray[][] = array();
      while ($currrow = @mysql_fetch_row($result))
      {
         $playerone = $currrow;
         $playertwo = @mysql_fetch_row($result);
         $resultArray[$count][] = $playerone[1];
         $resultArray[$count][] = $playerone[0];
         $resultArray[$count][] = $playertwo[1];
         $resultArray[$count][] = $playertwo[0];
         $count++;
         updateforeachrow($playerone, $playertwo);
      }
      generateDocument($resultArray, $count);
   }

    function generateDocument($resultArray, $count)
    {
        $output = fopen('php://temp/maxmemory'.(5*1024*1024), 'r+');
        $columns = array('Player One Col1', 'Player One Col2', 'Player Two Col1', 'Player Two Col2');
        fputcsv($output, $columns);
         for ($index=0 ; $index <=$count; $index++)
         {
            fputcsv($output, $resultArray[$index]);
         }
        rewind($output);
        $export = stream_get_contents($output);
        fclose($output);
        header('Content-type: application/octet-stream');
        header('Content-Disposition: attachment; filename = "export.csv"');
        echo $export;  
} 

However doing this outputs the entire html code to csv rather than specific rows. Can anyone please help me on this?

  • 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-05-23T01:44:31+00:00Added an answer on May 23, 2026 at 1:44 am

    . make string
    . output string to file
    . send header with (is this allowed this way?)

    use file_put_contents ( filename, str ), and than send it with headers.
    Make code simpler 🙂

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

Sidebar

Related Questions

I have run in to a bit of a problem and I have done
I have run across an XML Schema with the following definition: <xs:simpleType name=ClassRankType> <xs:restriction
I have run into a common, yet difficult problem. I do not use Photoshop
I have run into a bit of a tricky problem in some C++ code,
I have run into an issue with WPF and Commands that are bound to
I have run into a few cases where i have been asked to deploy
So I have run up against this problem a few times: I have some
it seems I have run into a problem with Internet Explorer 7. I have
I have been playing with javascript arrays and I have run into, what I
I just wanted some opinions from people that have run Selenium ( http://selenium.openqa.org )

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.