export data in excel

federici 23 Jul, 2012
Hi,
i have made a form for extract the data from my database, the form have 2 textbox date for to do research between 2 date and a radiobox for research in 2 different table "i need to choise table where i must to do the research"

I have used the the action Custom Code for do this, and for do displays the table screen, now i I would need insert a button in the page that if i push it the system made a excel file with the result of table, but I do not know how to do

this is my code


<?php
       
    $data1 = JRequest::getVar('data_1');
    $data2 = JRequest::getVar('data_2');
    $choice= JRequest::getVar('input_choice');
     
    if($choice=='B')
    {
      $db =& JFactory::getDBO();
      $query =  "SELECT DATE_FORMAT( cf_created, '%d-%m-%Y %H:%i:%s' ) AS data, id_broken, note_area 
                FROM #__app_broken 
                  WHERE cf_created BETWEEN '".$data1."' AND '".$data2."'";
      $db->setQuery($query);
      $row = $db->loadRowList();
      echo '<table><th>Data</th><th>ID</th><th>Note</th></tr>';
      foreach ($row as $key1=>$rw) {
          echo '<tr>';
    	     foreach ($rw as $key2=>$r) {
            echo '<td>' .$r. '</td>';
      	
        }
        echo '</tr>';
      }
      echo '</table>';   
    }
    else
    {
      $db =& JFactory::getDBO();
      $query =  "SELECT DATE_FORMAT( cf_created, '%d-%m-%Y %H:%i:%s' ) AS data, DATE_FORMAT( cf_modified, '%d-%m-%Y %H:%i:%s' ) AS modified, id_work   
                FROM #__app_work 
                  WHERE cf_created BETWEEN '".$data1."' AND '".$data2."'";
      $db->setQuery($query);
      $row = $db->loadRowList();
      echo '<table><th>Data</th><th>Modified</th><th>ID</th></tr>';
      foreach ($row as $key1=>$rw) {
          echo '<tr>';
    	     foreach ($rw as $key2=>$r) {
            echo '<td>' .$r. '</td>';
      	
        }
        echo '</tr>';
      }
      echo '</table>';
    }
     
?>


you can help me?

thanks
GreyHead 23 Jul, 2012
Hi federici,

I've never tried to so this. Here is one easy solution; does this help?

Bob
federici 23 Jul, 2012
i'm sorry but i don't understand

Your link is not very clear

i used this system because the action DB Multi Record Loader not allow me to find out which table to query

before i must do a query on db and after if is necessary to do the export
GreyHead 23 Jul, 2012
Hi federici,

I'm sorry but I don't understand your question.

Bob
This topic is locked and no more replies can be posted.