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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:08:45+00:00 2026-05-27T09:08:45+00:00

I am having a problem with my code. What it seems to be doing

  • 0

I am having a problem with my code. What it seems to be doing when I did a print_r of the returned array is that it has associative keys that have a value and then numeric keys that dont return a value, in the end when I output these array values to a .csv file it ends up doubling the information outputted and looks like the array is twice the size in the end. How can I fix my array so that the information is not doubled. My code is bellow:

              if ($_GET['do']=="export"){
        if (isset($_POST[format])){
            foreach ($_POST as $k=>$v){
                if (intval($k)>0){
                    $selstr[]="field$k";
                    $idstr[]=$k;
                }
            }
                if (is_array($selstr)){
//                  $data=$db->qarray("select ".implode(",",$selstr)." from business_db;");
                    $fields=$db->qarray("select * from business_fields where id in (".implode(",",$idstr).");");

                    $toget = "";

                    foreach($fields as $field)
                    {
                        $toget .= "field{$field[id]},";
                    }


                    $toget = substr($toget,0,strlen($toget)-1);                 

                    $dates = $db->qarray("SELECT * FROM business_years");


                    if ($_POST[format]=="csv"){
                        header("Pragma: public");
                        header("Expires: 0");
                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                        header("Content-Type: application/force-download");
                        header("Content-Type: application/octet-stream");
                        header("Content-Type: application/download");;
                        header("Content-Disposition: attachment;filename=export.csv ");
                        header("Content-Transfer-Encoding: binary ");
                        foreach($fields as $f){
                            $headers[]=$f[name];
                        }
                        echo implode(",",$headers);
                        echo "\n";
                        if ($_POST[filterdate]=="yes"){
                            //$sd=mktime(0,0,-1,intval($_POST[startmonth]),1,intval($_POST[startyear]));
                            //$ed=mktime(24,0,1,intval($_POST[endmonth]),date("t",mktime(1,1,1,intval($_POST[endmonth]),1,intval($_POST[endyear]))),intval($_POST[endyear]));
                            $ids = $db->qarray("SELECT DISTINCT bus_id FROM business_years WHERE date_registered BETWEEN '{$startyear}-{$startmonth}-00' and '{$endyear}-{$endmonth}-31'");

                            $idsa = "";
                            foreach($ids as $id)
                            {
                                $idsa .= $id[bus_id] . ",";
                            }

                            $idsa = substr($idsa,0,strlen($idsa)-1);


                            $records = $db->qarray("SELECT {$toget} FROM business_db WHERE id IN({$idsa})");

                            $output = "";
                            foreach($records as $record)
                            {
                                $output .= implode(",",$record) . "\n";
                            }

                            $rc = print_r($record,true);

                            $file = "debugdirectory.txt";
                            $fh = fopen($file,'w');

                            $string = $rc;



                            fwrite($fh,$string);
                            fclose($fh);

                            /*
                            foreach ($data as $d){
                                $cd=strtotime($d[field2]);
                                if ($cd > $sd and $cd < $ed){
                                $values=array();
                                foreach($fields as $f){
                                    $fname="field$f[id]";
                                    $values[]=$d[$fname];
                                }
                                echo implode(",",$values);
                                echo "\n";
                                }
                            }
                            */
                        }

When I do a print_r of $record it returns:

       Array
(
    [0] => 
    [field3] => 
    [1] => 
    [field4] => 
    [2] => 
    [field5] => 
    [3] => 
    [field6] => 
    [4] => 
    [field7] => 
    [5] => 
    [field8] => 
    [6] => 
    [field9] => 
    [7] => 
    [field10] => 
    [8] => 
    [field11] => 
    [9] => 
    [field13] => 
    [10] => 
    [field14] => 
    [11] => 
    [field15] => 
    [12] => 
    [field16] => 
    [13] => 
    [field17] => 
    [14] => 
    [field18] => 
    [15] => Regular
    [field19] => Regular
    [16] => 
    [field20] => 
    [17] => 
    [field21] => 
    [18] => Yes
    [field31] => Yes
    [19] => 
    [field23] => 
    [20] => 
    [field24] => 
    [21] => Yes
    [field30] => Yes
    [22] => 
    [field28] => 
    [23] => 01/01/2008,01/01/2009,01/01/2010
    [field32] => 01/01/2008,01/01/2009,01/01/2010
)
  • 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-27T09:08:45+00:00Added an answer on May 27, 2026 at 9:08 am

    Answer found quite some time ago!

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

Sidebar

Related Questions

I'm having a problem understanding what I'm doing wrong here. I have the code
So, i have this code that seems to be doing the mechanical work correctly,
I'm having a problem with some code that used to work in PHP 4.X
I'm having a problem with mixing managed and unmanaged code. I have created two
I'm having a problem with my Seam code and I can't seem to figure
I'm having a problem with some code I've written. I've had to anonymize it,
Having a problem with the dataGridView control being populated with Display members: Code: private
Having a problem getting a TreeView control to display node images. The code below
I'm having a problem getting a change event to register with the following code:
I'm having a problem with a query prepared in PHP with PDO. The code:

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.