title: Codeigniter - Export Database data in DOC format
body: <p>I want to export data in my MYSQL Database into a DOC file using Codeigniter. 
  My code is as follows:</p>
  
  <p>view named 'profile_top_view.php' where anchor is declared as :</p>
  
  <pre><code>&lt;?php echo anchor('welcome/todoc','Export Posts to DOC File') ?&gt;
  </code></pre>
  
  <p>controller named 'welcome.php' has function :</p>
  
  <pre><code> public function todoc() {
      $id = $this-&gt;tank_auth-&gt;get_user_id();
      $this-&gt;mpdf-&gt;useOnlyCoreFonts = true;
      $filename = "POSTS";
      $data['member'] = $this-&gt;s_model-&gt;alldata($id);
      $this-&gt;load-&gt;view('export_posts_doc_view', $data, true);
      $this-&gt;index();
  }
  </code></pre>
  
  <p>A view named 'export_posts_doc_view.php', where a table will be created for the DOC file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;Exported Posts in PDF File&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php
          header("Content-Type: application/vnd.ms-word");
          header("Expires: 0");
          header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
          header("Content-disposition: attachment; filename=\"posts.doc\"");
          ?&gt;
  
  
          &lt;div id="container"&gt;
              &lt;h4&gt;Posts&lt;/h4&gt;
              &lt;table border="1"&gt;
                  &lt;tr&gt;
                      &lt;th&gt;title&lt;/th&gt;
                      &lt;th&gt;content&lt;/th&gt;
                      &lt;th&gt;group&lt;/th&gt;
                      &lt;th&gt;video_url&lt;/th&gt;
                      &lt;th&gt;pic_path&lt;/th&gt;
                      &lt;th&gt;name&lt;/th&gt;
                      &lt;th&gt;phone&lt;/th&gt;
                      &lt;th&gt;email&lt;/th&gt;
                      &lt;th&gt;yes_no&lt;/th&gt;
                      &lt;th&gt;single-line-text&lt;/th&gt;
                      &lt;th&gt;para_text&lt;/th&gt;
                      &lt;th&gt;pdf_file_name&lt;/th&gt;
                      &lt;th&gt;add_photo_name&lt;/th&gt;
                  &lt;/tr&gt;
  &lt;?php
  foreach ($member as $rows) {
      ?&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $rows['title'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['content'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['group'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['video_url'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['pic_path'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['name'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['phone'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['email'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['yes_no'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['single-line-text'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['para_text'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['pdf_file_name'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $rows['add_photo_name'] ?&gt;&lt;/td&gt;
                      &lt;/tr&gt;
      &lt;?php
  }
  ?&gt;
              &lt;/table&gt;
  
              &lt;br&gt; &lt;br&gt;
  
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and also a model named 's_model.php', having function :</p>
  
  <pre><code>  function alldata($id)
      {
          $this-&gt;db-&gt;select('');
          $this-&gt;db-&gt;from('posts');
              $this-&gt;db-&gt;where('user-id',$id);
          $getData = $this-&gt;db-&gt;get();
          if($getData-&gt;num_rows() &gt; 0)
          return $getData-&gt;result_array();
          else return null;
      }
  </code></pre>
  
  <p>If I keep that header there, then it is showing error as:</p>
  
  <blockquote>
    <p>No webpage was found for the web address:
    <a href="http://www.my_ip.com/project/welcome/todoc" rel="nofollow noreferrer">http://www.my_ip.com/project/welcome/todoc</a></p>
  </blockquote>
  
  <p>But, if I remove the same header, it shows the things echoed in the controller.
  I have got that header from the following URL:
  <a href="https://stackoverflow.com/questions/6172461/exporting-ms-word-documents-using-codeigniter">exporting MS word documents using codeigniter?</a></p>
  
  <p>Can anyone please let me know what should I do with that?</p>
  
  <p>Thanks in advance..</p>