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

  • SEARCH
  • Home
  • 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 875295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:14:43+00:00 2026-05-15T11:14:43+00:00

The code I currently have: <?php /** PHPExcel */ require_once ‘../Classes/PHPExcel.php’; /** PHPExcel_IOFactory */

  • 0

The code I currently have:

<?php

  /** PHPExcel */
  require_once '../Classes/PHPExcel.php';

  /** PHPExcel_IOFactory */
  require_once '../Classes/PHPExcel/IOFactory.php';

  // Create new PHPExcel object
  $objPHPExcel = new PHPExcel();

  // Set properties
  $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                               ->setLastModifiedBy("Maarten Balliauw")
                               ->setTitle("Office 2007 XLSX Test Document")
                               ->setSubject("Office 2007 XLSX Test Document")
                               ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                               ->setKeywords("office 2007 openxml php")
                               ->setCategory("Test result file");

  $result = 'select * from table1';

  for($i=0;$i<count($result);$i++) {

    $result1 = 'select * from table2 where table1_id = ' . $result[$i]['table1_id'];

    for ($j=0;$j<count($result1);$j++) {
      $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $j, $result1[$j]['name']);
    }

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    // Save Excel 2007 file
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));

    // Echo done
    echo date('H:i:s') . " Done writing file.\r\n";       
  }

?>

The above code executes and save n no of .xlsx files in the folder, but the problem I’m getting is biggest count(result1) in the for loop executing in all saved excel files.

  • 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-15T11:14:44+00:00Added an answer on May 15, 2026 at 11:14 am

    Before going deep, one thing is clear

    You haven’t executed the query for $result, neither fetch it and on $result1 query you are using it which is not possible,

    Same problem exist with $result1

    You can use:

    $result = mysql_query('select * from table1');
    while($fetch_result=mysql_fetch_array($result))
    {
        $result2 = mysql("select * from table2 where table1_id = '".$fetch_result['table1_id']."'");
    
       while($fetch_result2=mysql_fetch_array($result2)
       {
        --your code--
    

    But it is preferable to write JOIN instead of these two query

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

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In ASIHTTPRequest.m, look in the -checkRequestStatus method. When a timeout… May 16, 2026 at 12:39 am
  • Editorial Team
    Editorial Team added an answer I think your culprit may be this line: Dim insertingCells(originalRow.Cells.Count)… May 16, 2026 at 12:39 am
  • Editorial Team
    Editorial Team added an answer I could tell you what we do: We have a… May 16, 2026 at 12:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.