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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:01:54+00:00 2026-06-13T22:01:54+00:00

I’m using PHPExcel to export data from a MYSQL database and import it into

  • 0

I’m using PHPExcel to export data from a MYSQL database and import it into an excel file.

I’ve got a database that looks like this (this is also what my excel file currently looks like when I generate it using PHPExcel):

======================================================
|           Question                  |   Answer     |
=========+===========+===============================|
| Do you listen to music?             |    YES       |            
|----------------------------------------------------|
| Who is your favorite music artists? | Justin Beiber| 
|----------------------------------------------------|
| <p> Select an Answer<p>             |              | 
|----------------------------------------------------|
|Are you a Male or female             |      M       | 
|----------------------------------------------------|

I want my excel file to look like this:

======================================================
|           Question                  |   Answer     |
=========+===========+===============================|
| Do you listen to music?             |    YES       |            
|----------------------------------------------------|
| Who is your favorite music artists? | Justin Beiber| 
|----------------------------------------------------|
|Are you a Male or female             |      M       | 
|----------------------------------------------------|

I’m using this code:

$objPHPExcel = new PHPExcel();

$col = 1; 
while($row_data = mysql_fetch_assoc($result)) {
    $row = 1;
    if ($col == 1) {
        $row_headings = array_keys($row_data);
        foreach($row_headings as $value) {
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
            $row++;
        }
        $row = 1;
        $col++;
    }
    foreach($row_data as $value) {
      if (!strstr('<p>', $value)){
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);

    $row++;
         }
    }
    $col++;
}
  • 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-13T22:01:56+00:00Added an answer on June 13, 2026 at 10:01 pm

    One option would be to exclude the <p> Select an Answer<p> when doing a SQL query you would SELECT your columns and rows then from your selection you could DELETE WHERE question = "<p> Select an Answer<p> "

    Or if column Anwser value is null or "" when Question value is <p> Select an Answer<p>, then you can could also say:

    if($value !== null)
    {
      // Output...
    } 
    

    In example:

    $objPHPExcel = new PHPExcel();
    
    $col = 1; 
    while($row_data = mysql_fetch_assoc($result)) {
        $row = 1;
        if ($col == 1) {
            $row_headings = array_keys($row_data);
            foreach($row_headings as $value) {
                $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
                $row++;
            }
            $row = 1;
            $col++;
        }
        foreach($row_data as $value) {
            if($value !== null || $value !== '')
            {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
             $row++;
            }
        }
        $col++;
    }
    

    Or you could simply delete rows that contain <p> Select an Answer<p> unless you need them.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.