Export php to csv without query OR





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a php query working with no problems. However, prior to exporting to a csv file, I need to use a regular expressions to customize the look of a few variables. I have this working as well.



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


My problem is that I need to export these customized variables, instead of the raw query results.



Is this possible?



Also,



I have been trying to use a regular expression in mysql 5.7 but have had no luck.
Is there a preg_replace equivalent in MySQL 5.7?
I haven't found one yet. There seems to be one in MySQL 7 but I cannot upgrade yet.



my php that I would like to find an mysql equivalent for:



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


I tried below but it does not work.



REPLACE(fd.form_field_number, '(W{3}.*)', 'n', 1, 5) AS New_Field 


Thanks for any assistance, even if it is "look over here..."



Revised::



I have a checkbox group column where the results are:



result 1|~|result 1
result 2|~|result 2
result 3|~|result 3


The regex removes the |~| and everything to the right of it, so the results are:



result 1
result 2
result 3


I can do this in php but need to get these results into a downloadable csv file.










share|improve this question

























  • I am really bad in regex (preg_replace). so what are you trying to replace?

    – ratmalwer
    Nov 16 '18 at 20:04













  • I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

    – user1469
    Nov 16 '18 at 20:13




















1















I have a php query working with no problems. However, prior to exporting to a csv file, I need to use a regular expressions to customize the look of a few variables. I have this working as well.



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


My problem is that I need to export these customized variables, instead of the raw query results.



Is this possible?



Also,



I have been trying to use a regular expression in mysql 5.7 but have had no luck.
Is there a preg_replace equivalent in MySQL 5.7?
I haven't found one yet. There seems to be one in MySQL 7 but I cannot upgrade yet.



my php that I would like to find an mysql equivalent for:



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


I tried below but it does not work.



REPLACE(fd.form_field_number, '(W{3}.*)', 'n', 1, 5) AS New_Field 


Thanks for any assistance, even if it is "look over here..."



Revised::



I have a checkbox group column where the results are:



result 1|~|result 1
result 2|~|result 2
result 3|~|result 3


The regex removes the |~| and everything to the right of it, so the results are:



result 1
result 2
result 3


I can do this in php but need to get these results into a downloadable csv file.










share|improve this question

























  • I am really bad in regex (preg_replace). so what are you trying to replace?

    – ratmalwer
    Nov 16 '18 at 20:04













  • I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

    – user1469
    Nov 16 '18 at 20:13
















1












1








1








I have a php query working with no problems. However, prior to exporting to a csv file, I need to use a regular expressions to customize the look of a few variables. I have this working as well.



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


My problem is that I need to export these customized variables, instead of the raw query results.



Is this possible?



Also,



I have been trying to use a regular expression in mysql 5.7 but have had no luck.
Is there a preg_replace equivalent in MySQL 5.7?
I haven't found one yet. There seems to be one in MySQL 7 but I cannot upgrade yet.



my php that I would like to find an mysql equivalent for:



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


I tried below but it does not work.



REPLACE(fd.form_field_number, '(W{3}.*)', 'n', 1, 5) AS New_Field 


Thanks for any assistance, even if it is "look over here..."



Revised::



I have a checkbox group column where the results are:



result 1|~|result 1
result 2|~|result 2
result 3|~|result 3


The regex removes the |~| and everything to the right of it, so the results are:



result 1
result 2
result 3


I can do this in php but need to get these results into a downloadable csv file.










share|improve this question
















I have a php query working with no problems. However, prior to exporting to a csv file, I need to use a regular expressions to customize the look of a few variables. I have this working as well.



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


My problem is that I need to export these customized variables, instead of the raw query results.



Is this possible?



Also,



I have been trying to use a regular expression in mysql 5.7 but have had no luck.
Is there a preg_replace equivalent in MySQL 5.7?
I haven't found one yet. There seems to be one in MySQL 7 but I cannot upgrade yet.



my php that I would like to find an mysql equivalent for:



$form_field_number_UPD = preg_replace('(W{3}.*)', 'n', $form_field_number);


I tried below but it does not work.



REPLACE(fd.form_field_number, '(W{3}.*)', 'n', 1, 5) AS New_Field 


Thanks for any assistance, even if it is "look over here..."



Revised::



I have a checkbox group column where the results are:



result 1|~|result 1
result 2|~|result 2
result 3|~|result 3


The regex removes the |~| and everything to the right of it, so the results are:



result 1
result 2
result 3


I can do this in php but need to get these results into a downloadable csv file.







php mysql export-to-csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 20:21









alexis

34.6k1061121




34.6k1061121










asked Nov 16 '18 at 19:40









user1469user1469

113




113













  • I am really bad in regex (preg_replace). so what are you trying to replace?

    – ratmalwer
    Nov 16 '18 at 20:04













  • I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

    – user1469
    Nov 16 '18 at 20:13





















  • I am really bad in regex (preg_replace). so what are you trying to replace?

    – ratmalwer
    Nov 16 '18 at 20:04













  • I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

    – user1469
    Nov 16 '18 at 20:13



















I am really bad in regex (preg_replace). so what are you trying to replace?

– ratmalwer
Nov 16 '18 at 20:04







I am really bad in regex (preg_replace). so what are you trying to replace?

– ratmalwer
Nov 16 '18 at 20:04















I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

– user1469
Nov 16 '18 at 20:13







I have a checkbox group column where the results are: result 1|~|result 1 result 2|~|result 2 result 3|~|result 3 The regex removes the |~| and everything to the right of it, so the results are: result 1 result 2 result 3 I can do this in php but need to get these results into a downloadable csv file.

– user1469
Nov 16 '18 at 20:13














3 Answers
3






active

oldest

votes


















1














I would suggest getting an array of the data you'd like to export into php using a MySQL SELECT query and using your php preg_replace() statement since you know that works. Exporting the replaced data to a csv file from the php array is pretty straightforward from there.



This link has answers with code samples of how this can be done: Export to CSV via PHP






share|improve this answer































    1














    If your column is always demarcated with the symbol |~|, you don't need a regular expression; look for occurrences of this exact sequence, and use SUBSTR to chop off the rest of your string:



    SELECT SUBSTR(fd.form_field_number, 1, LOCATE('|~|', fd.form_field_number)-1) AS trimmed
    FROM ...





    share|improve this answer
























    • This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

      – user1469
      Nov 16 '18 at 20:44











    • dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

      – alexis
      Nov 16 '18 at 20:52











    • What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

      – alexis
      Nov 16 '18 at 21:00





















    0














    Well, I am half way there. I did need to use php and I have the php working on the display end. What I need to do now is turn the results into an array and pass that to the csv export.



    I need to pass the php results from the foreach and not from the query result because I need to use the regular expression to adjust on column of results.



    I though I could use the $res_UPD or $list array but no success there.



    Below is what I have used so far. I am confused about where to put the function for the output as well as generate the csv file. Above or below the foreach?



    Any help is appreciated and if to let me know that I am way off base and look...



        header("Content-Type: text/csv");
    header("Content-Disposition: attachment; filename=$q1b.csv");

    switch( $q1b )
    {
    case "research-request":


    $query = "SELECT
    DATE_FORMAT(FROM_UNIXTIME(fd.entry_date), '%Y-%m-%d') AS date_formatted,
    fd.entry_id,
    fd.form_field_1 AS FIRST_NAME,
    fd.form_field_2 AS LAST_NAME,
    fd.form_field_3 AS EMAIL,
    fd.form_field_957 AS checkbox_field, /* checkbox group */
    FROM db_table AS fd
    WHERE 1 ORDER BY date_formatted DESC";
    break;

    }

    $res = $this->EE->db->query($query);

    if ($res->num_rows() > 0)
    {

    foreach($res->result_array() as $row)
    {
    $date_formatted = $row['date_formatted'];
    $FIRST_NAME = $row['FIRST_NAME'];
    $LAST_NAME = $row['LAST_NAME'];
    $EMAIL = $row['EMAIL'];
    $checkbox_field = $row['checkbox_field'];
    $checkbox_field_UPD = preg_replace('(W{3}.*)', 'n', $checkbox_field);

    $res_UPD =
    $date_formatted.",".$FIRST_NAME.",".$LAST_NAME.",".$EMAIL.",".$checkbox_field_UPD;

    $list = array($date_formatted,$FIRST_NAME,$LAST_NAME,$EMAIL,$checkbox_field_UPD);

    }

    }





    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344344%2fexport-php-to-csv-without-query-or%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I would suggest getting an array of the data you'd like to export into php using a MySQL SELECT query and using your php preg_replace() statement since you know that works. Exporting the replaced data to a csv file from the php array is pretty straightforward from there.



      This link has answers with code samples of how this can be done: Export to CSV via PHP






      share|improve this answer




























        1














        I would suggest getting an array of the data you'd like to export into php using a MySQL SELECT query and using your php preg_replace() statement since you know that works. Exporting the replaced data to a csv file from the php array is pretty straightforward from there.



        This link has answers with code samples of how this can be done: Export to CSV via PHP






        share|improve this answer


























          1












          1








          1







          I would suggest getting an array of the data you'd like to export into php using a MySQL SELECT query and using your php preg_replace() statement since you know that works. Exporting the replaced data to a csv file from the php array is pretty straightforward from there.



          This link has answers with code samples of how this can be done: Export to CSV via PHP






          share|improve this answer













          I would suggest getting an array of the data you'd like to export into php using a MySQL SELECT query and using your php preg_replace() statement since you know that works. Exporting the replaced data to a csv file from the php array is pretty straightforward from there.



          This link has answers with code samples of how this can be done: Export to CSV via PHP







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 20:18









          GrantSlayGrantSlay

          1175




          1175

























              1














              If your column is always demarcated with the symbol |~|, you don't need a regular expression; look for occurrences of this exact sequence, and use SUBSTR to chop off the rest of your string:



              SELECT SUBSTR(fd.form_field_number, 1, LOCATE('|~|', fd.form_field_number)-1) AS trimmed
              FROM ...





              share|improve this answer
























              • This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

                – user1469
                Nov 16 '18 at 20:44











              • dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

                – alexis
                Nov 16 '18 at 20:52











              • What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

                – alexis
                Nov 16 '18 at 21:00


















              1














              If your column is always demarcated with the symbol |~|, you don't need a regular expression; look for occurrences of this exact sequence, and use SUBSTR to chop off the rest of your string:



              SELECT SUBSTR(fd.form_field_number, 1, LOCATE('|~|', fd.form_field_number)-1) AS trimmed
              FROM ...





              share|improve this answer
























              • This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

                – user1469
                Nov 16 '18 at 20:44











              • dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

                – alexis
                Nov 16 '18 at 20:52











              • What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

                – alexis
                Nov 16 '18 at 21:00
















              1












              1








              1







              If your column is always demarcated with the symbol |~|, you don't need a regular expression; look for occurrences of this exact sequence, and use SUBSTR to chop off the rest of your string:



              SELECT SUBSTR(fd.form_field_number, 1, LOCATE('|~|', fd.form_field_number)-1) AS trimmed
              FROM ...





              share|improve this answer













              If your column is always demarcated with the symbol |~|, you don't need a regular expression; look for occurrences of this exact sequence, and use SUBSTR to chop off the rest of your string:



              SELECT SUBSTR(fd.form_field_number, 1, LOCATE('|~|', fd.form_field_number)-1) AS trimmed
              FROM ...






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 16 '18 at 20:37









              alexisalexis

              34.6k1061121




              34.6k1061121













              • This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

                – user1469
                Nov 16 '18 at 20:44











              • dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

                – alexis
                Nov 16 '18 at 20:52











              • What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

                – alexis
                Nov 16 '18 at 21:00





















              • This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

                – user1469
                Nov 16 '18 at 20:44











              • dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

                – alexis
                Nov 16 '18 at 20:52











              • What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

                – alexis
                Nov 16 '18 at 21:00



















              This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

              – user1469
              Nov 16 '18 at 20:44





              This would be perfect but I need to add a replace. My bad for not mentioning that the code I listed above is from a column in one row. So technically it looks like: result 1|~|result 1nresult 2|~|result 2nresult 3|~|result 3. so I would need to somehow combine the replace and substr. Is this possible?

              – user1469
              Nov 16 '18 at 20:44













              dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

              – alexis
              Nov 16 '18 at 20:52





              dev.mysql.com/doc/refman/5.7/en/string-functions.html. See if there's anything else you need there, while you are at it.

              – alexis
              Nov 16 '18 at 20:52













              What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

              – alexis
              Nov 16 '18 at 21:00







              What kind of "data" is this, anyway? If this kind of material is in a single database cell, you are not really dealing with relational data and shouldn't try to do the whole job with SQL. Pull it into php, go to town with regexp_replace() and its friends, and write out the results with fputcsv().

              – alexis
              Nov 16 '18 at 21:00













              0














              Well, I am half way there. I did need to use php and I have the php working on the display end. What I need to do now is turn the results into an array and pass that to the csv export.



              I need to pass the php results from the foreach and not from the query result because I need to use the regular expression to adjust on column of results.



              I though I could use the $res_UPD or $list array but no success there.



              Below is what I have used so far. I am confused about where to put the function for the output as well as generate the csv file. Above or below the foreach?



              Any help is appreciated and if to let me know that I am way off base and look...



                  header("Content-Type: text/csv");
              header("Content-Disposition: attachment; filename=$q1b.csv");

              switch( $q1b )
              {
              case "research-request":


              $query = "SELECT
              DATE_FORMAT(FROM_UNIXTIME(fd.entry_date), '%Y-%m-%d') AS date_formatted,
              fd.entry_id,
              fd.form_field_1 AS FIRST_NAME,
              fd.form_field_2 AS LAST_NAME,
              fd.form_field_3 AS EMAIL,
              fd.form_field_957 AS checkbox_field, /* checkbox group */
              FROM db_table AS fd
              WHERE 1 ORDER BY date_formatted DESC";
              break;

              }

              $res = $this->EE->db->query($query);

              if ($res->num_rows() > 0)
              {

              foreach($res->result_array() as $row)
              {
              $date_formatted = $row['date_formatted'];
              $FIRST_NAME = $row['FIRST_NAME'];
              $LAST_NAME = $row['LAST_NAME'];
              $EMAIL = $row['EMAIL'];
              $checkbox_field = $row['checkbox_field'];
              $checkbox_field_UPD = preg_replace('(W{3}.*)', 'n', $checkbox_field);

              $res_UPD =
              $date_formatted.",".$FIRST_NAME.",".$LAST_NAME.",".$EMAIL.",".$checkbox_field_UPD;

              $list = array($date_formatted,$FIRST_NAME,$LAST_NAME,$EMAIL,$checkbox_field_UPD);

              }

              }





              share|improve this answer




























                0














                Well, I am half way there. I did need to use php and I have the php working on the display end. What I need to do now is turn the results into an array and pass that to the csv export.



                I need to pass the php results from the foreach and not from the query result because I need to use the regular expression to adjust on column of results.



                I though I could use the $res_UPD or $list array but no success there.



                Below is what I have used so far. I am confused about where to put the function for the output as well as generate the csv file. Above or below the foreach?



                Any help is appreciated and if to let me know that I am way off base and look...



                    header("Content-Type: text/csv");
                header("Content-Disposition: attachment; filename=$q1b.csv");

                switch( $q1b )
                {
                case "research-request":


                $query = "SELECT
                DATE_FORMAT(FROM_UNIXTIME(fd.entry_date), '%Y-%m-%d') AS date_formatted,
                fd.entry_id,
                fd.form_field_1 AS FIRST_NAME,
                fd.form_field_2 AS LAST_NAME,
                fd.form_field_3 AS EMAIL,
                fd.form_field_957 AS checkbox_field, /* checkbox group */
                FROM db_table AS fd
                WHERE 1 ORDER BY date_formatted DESC";
                break;

                }

                $res = $this->EE->db->query($query);

                if ($res->num_rows() > 0)
                {

                foreach($res->result_array() as $row)
                {
                $date_formatted = $row['date_formatted'];
                $FIRST_NAME = $row['FIRST_NAME'];
                $LAST_NAME = $row['LAST_NAME'];
                $EMAIL = $row['EMAIL'];
                $checkbox_field = $row['checkbox_field'];
                $checkbox_field_UPD = preg_replace('(W{3}.*)', 'n', $checkbox_field);

                $res_UPD =
                $date_formatted.",".$FIRST_NAME.",".$LAST_NAME.",".$EMAIL.",".$checkbox_field_UPD;

                $list = array($date_formatted,$FIRST_NAME,$LAST_NAME,$EMAIL,$checkbox_field_UPD);

                }

                }





                share|improve this answer


























                  0












                  0








                  0







                  Well, I am half way there. I did need to use php and I have the php working on the display end. What I need to do now is turn the results into an array and pass that to the csv export.



                  I need to pass the php results from the foreach and not from the query result because I need to use the regular expression to adjust on column of results.



                  I though I could use the $res_UPD or $list array but no success there.



                  Below is what I have used so far. I am confused about where to put the function for the output as well as generate the csv file. Above or below the foreach?



                  Any help is appreciated and if to let me know that I am way off base and look...



                      header("Content-Type: text/csv");
                  header("Content-Disposition: attachment; filename=$q1b.csv");

                  switch( $q1b )
                  {
                  case "research-request":


                  $query = "SELECT
                  DATE_FORMAT(FROM_UNIXTIME(fd.entry_date), '%Y-%m-%d') AS date_formatted,
                  fd.entry_id,
                  fd.form_field_1 AS FIRST_NAME,
                  fd.form_field_2 AS LAST_NAME,
                  fd.form_field_3 AS EMAIL,
                  fd.form_field_957 AS checkbox_field, /* checkbox group */
                  FROM db_table AS fd
                  WHERE 1 ORDER BY date_formatted DESC";
                  break;

                  }

                  $res = $this->EE->db->query($query);

                  if ($res->num_rows() > 0)
                  {

                  foreach($res->result_array() as $row)
                  {
                  $date_formatted = $row['date_formatted'];
                  $FIRST_NAME = $row['FIRST_NAME'];
                  $LAST_NAME = $row['LAST_NAME'];
                  $EMAIL = $row['EMAIL'];
                  $checkbox_field = $row['checkbox_field'];
                  $checkbox_field_UPD = preg_replace('(W{3}.*)', 'n', $checkbox_field);

                  $res_UPD =
                  $date_formatted.",".$FIRST_NAME.",".$LAST_NAME.",".$EMAIL.",".$checkbox_field_UPD;

                  $list = array($date_formatted,$FIRST_NAME,$LAST_NAME,$EMAIL,$checkbox_field_UPD);

                  }

                  }





                  share|improve this answer













                  Well, I am half way there. I did need to use php and I have the php working on the display end. What I need to do now is turn the results into an array and pass that to the csv export.



                  I need to pass the php results from the foreach and not from the query result because I need to use the regular expression to adjust on column of results.



                  I though I could use the $res_UPD or $list array but no success there.



                  Below is what I have used so far. I am confused about where to put the function for the output as well as generate the csv file. Above or below the foreach?



                  Any help is appreciated and if to let me know that I am way off base and look...



                      header("Content-Type: text/csv");
                  header("Content-Disposition: attachment; filename=$q1b.csv");

                  switch( $q1b )
                  {
                  case "research-request":


                  $query = "SELECT
                  DATE_FORMAT(FROM_UNIXTIME(fd.entry_date), '%Y-%m-%d') AS date_formatted,
                  fd.entry_id,
                  fd.form_field_1 AS FIRST_NAME,
                  fd.form_field_2 AS LAST_NAME,
                  fd.form_field_3 AS EMAIL,
                  fd.form_field_957 AS checkbox_field, /* checkbox group */
                  FROM db_table AS fd
                  WHERE 1 ORDER BY date_formatted DESC";
                  break;

                  }

                  $res = $this->EE->db->query($query);

                  if ($res->num_rows() > 0)
                  {

                  foreach($res->result_array() as $row)
                  {
                  $date_formatted = $row['date_formatted'];
                  $FIRST_NAME = $row['FIRST_NAME'];
                  $LAST_NAME = $row['LAST_NAME'];
                  $EMAIL = $row['EMAIL'];
                  $checkbox_field = $row['checkbox_field'];
                  $checkbox_field_UPD = preg_replace('(W{3}.*)', 'n', $checkbox_field);

                  $res_UPD =
                  $date_formatted.",".$FIRST_NAME.",".$LAST_NAME.",".$EMAIL.",".$checkbox_field_UPD;

                  $list = array($date_formatted,$FIRST_NAME,$LAST_NAME,$EMAIL,$checkbox_field_UPD);

                  }

                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 20:17









                  user1469user1469

                  113




                  113






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344344%2fexport-php-to-csv-without-query-or%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine