Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.77 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP - I cannot correctly display data in xls file (exported from mysql))
  2. Id    Registration_id    Question_id    Answer
  3. 1     Reg01                 1            John
  4. 2     Reg01                 2            Smith
  5. 3     Reg01                 3            name@domain.com
  6. 4     Reg02                 1            Rachel
  7. 5     Reg02                 2            Smith
  8. 6     Reg02                 3            name2@domain.com
  9.        
  10. Name   SecondName  Email
  11. John    Smith      name@domain.com  
  12. Rachel  Smith      name2@domain.com
  13.        
  14. $conn = mysql_connect("localhost","form","pass");
  15. $db = mysql_select_db("form",$conn);
  16.  
  17.  
  18. $query = "SELECT DISTINCT wp_events_question.question as qst, wp_events_answer.answer as ans
  19. FROM wp_events_question, wp_events_answer
  20. WHERE wp_events_question.id = wp_events_answer.question_id";
  21.  
  22. $query2 = "SELECT wp_events_question.question as qst, wp_events_answer.answer as ans
  23. FROM wp_events_question, wp_events_answer
  24. WHERE wp_events_question.id = wp_events_answer.question_id and wp_events_detail.id = wp_events_attendee.event_id AND wp_events_attendee.id = wp_events_answer.attendee_id";
  25.  
  26. $result = mysql_query($query) or die(mysql_error()); //Headers  
  27.  
  28.  $result2 = mysql_query($query2) or die(mysql_error()); //Answers  
  29.  
  30.     //Headers
  31.             $tbl= " <table border='1'>";
  32.  
  33.             $tbl= $tbl . "<tr height='50px'>";
  34.  
  35.             while($row = mysql_fetch_array($result))
  36.             {      
  37.                 $tbl= $tbl . "<td WIDTH='50px' align='center'>".$row['qst']."</td>";                
  38.             }  
  39.  
  40.  
  41.  
  42.    //Answers    
  43.                 $tbl = $tbl . "</tr>";  
  44.                 $tbl = $tbl . "<tr>";
  45.             while($row2 = mysql_fetch_array($result2))
  46.             {
  47.  
  48.                 $tbl= $tbl . "<td WIDTH='50px' align='center'>".$row2['ans']."</td>";
  49.  
  50.             }
  51.             $tbl = $tbl . "</tr>";
  52.             $tbl = $tbl . "</table>";
  53.  
  54.  
  55.             header("Cache-Control: no-stor,no-cache,must-revalidate");
  56.             header("Cache-Control: post-check=0,pre-check=0", false);
  57.             header("Cache-control: private");
  58.             header("Content-Type: application/force-download");
  59.             header("Content-Disposition: inline; attachment;filename=Reservations.xls");
  60.             header("Content-Transfer-Encoding: binary");
  61.             header("Pragma: no-cache");
  62.             header("Expires: 0");
  63.  
  64.             print $tbl;
  65.        
  66. $tbl = $tbl . "<tr>";
  67.         while($row2 = mysql_fetch_array($result2))  
  68.         {
  69.  
  70.             $tbl= $tbl . "<td WIDTH='50px' align='center'>".$row2['ans']."</td>";
  71.  
  72.         }
  73.         $tbl = $tbl . "</tr>";
  74.        
  75. while($row2 = mysql_fetch_array($result2))  
  76.         {
  77.             $tbl = $tbl . "<tr>";
  78.             $tbl = $tbl . "<td WIDTH='50px' align='center'>".$row2['ans']."</td>";
  79.             $tbl = $tbl . "</tr>";
  80.         }