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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:52:19+00:00 2026-06-13T21:52:19+00:00

What am I doing wrong here. I want the array we get at first

  • 0

What am I doing wrong here. I want the array we get at first to be transposed. Then the regex breakups one of the columns so we can query another table in the database to replace that column header with the correct header. Is the Regex correct? Is the transpose correct?

This will get the query we want

exportMysqlToCsv($tablename,$tokenmain, $id);
function exportMysqlToCsv($tablename,$tokenmain, $id, $filename = 'Results.csv'){
      $sql_query = "select * from $tablename where $tokenmain";

// Gets the data from the database

$result = mysql_query($sql_query);


$f = fopen('php://temp', 'wt');
$first = true;

$temp = mysql_fetch_array($result);

I hope this transposes the array we just got . Not sure here

array_unshift($temp, null);
$transposed_array = call_user_func_array('array_map', $temp);

Then we loop through transposed-array an replace the column header we receive (ex. 111X2222X3333) and split these up to query the headers we want to replace them with and output it to the excel file. This is where I am very confused.

for ($i = 0; $i < $count; $i++) {
if ($transposed_array[$i][0])//starts with a number
{
    $sid = regexp /^[0-9]*/

    $gid = regexp /X[0-9]*X/
    //remove first and last character from $gid
    $gid = str_replace("X", "", $gid)

    $qid = regexp /[0-9]*$/

    $question_text = mysql_query("select question from lime_questions where sid =           ".$sid." and gid = ".$gid." and qid = ".$qid." limit 1");
    $transposed_array[$i][5] = $question_test
}

This should output the array to the csv file

while ($row = mysql_fetch_assoc($result))
{
         if ($first)
     {
            fputcsv($f, array_keys($row));
            $first = false;
     }
fputcsv($f, $row);

} // end while

//resume normal processing

$size = ftell($f);
rewind($f);
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: $size");

// Output to browser with appropriate mime type, you choose 😉

header("Content-type: text/x-csv");
header("Content-type: text/csv");
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=$filename");

fpassthru($f);

exit;
  • 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-13T21:52:21+00:00Added an answer on June 13, 2026 at 9:52 pm

    Not sure what you want to achieve because the folloing are not valid PHP expressions

      $sid = regexp /^[0-9]*/
      $gid = regexp /X[0-9]*X/
      $qid = regexp /[0-9]*$/
    

    But form your comments

    I want this loop to split up the column headers we recieve from the first array. An example of a column header is 111X222X3333. I want to split them up using regex so each one is its own attribute like sid =111 gid=222 and qid=3333

    All you need is

    $string = "111X222X3333" ;
    list($sid,$gid,$qid) = explode("X", $string);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I don't understand what I am doing wrong here. I want to populate
What am I doing wrong here? I'm trying to get started with jQuery UI
I'm new to Java so I'm probably doing something wrong here, I want to
What am I doing wrong here folks? <?php include 'header.php'; /** * Display a
What am I doing wrong here: class Helo { // main: generate some simple
What am I doing wrong here? I'm serializing a value, storing it in a
What am I doing wrong here? private void SendMail(string from, string body) { string
What am I doing wrong here? Im trying to save a canvas drawing by
What am I doing wrong here? It says Database Count Failed (on the $count
What am I doing wrong here? Declare @starttimestamp datetime = getdate(); RAISERROR(N'Code not valid

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.