Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.00 KB | None | 0 0
  1. <?php
  2.  
  3. header("Content-Type: application/vnd.ms-excel");
  4. header("Content-disposition: attachment; filename=spreadsheet.xls");
  5.  
  6. $link = mysqli_connect("localhost", "root", "root", "sjp");
  7.  
  8. if (!$link) {
  9.     echo "Error: Unable to connect to MySQL." . PHP_EOL;
  10.     echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
  11.     echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
  12.     exit;
  13. }
  14.  
  15. $sql = "SELECT  exp_channel_titles.status, exp_channel_titles.entry_date, exp_channel_data.field_id_27, exp_channel_data.field_id_20, exp_channel_data.field_id_28, exp_channel_data.field_id_3, exp_channel_data.field_id_5, exp_channel_data.field_id_21 FROM exp_channel_titles JOIN exp_channel_data ON exp_channel_titles.entry_id = exp_channel_data.entry_id AND exp_channel_titles.status='open';";
  16.  
  17. $result = $link->query($sql);
  18.  
  19. //Set the column headings in the speadsheet
  20. echo   "Status".
  21.         "\t" . 'First Name' .
  22.         "\t" . 'Last Name' .
  23.         "\t" . 'Email' .
  24.         "\t" . 'Partner Name' .
  25.         "\t" . 'Startup' .
  26.         "\t" . 'Cashflow' .
  27.         "\t" . 'Reliefs' .
  28.         "\t" . 'Risks'.
  29.         "\t" . 'Rewarding' .
  30.         "\t" . 'Senior'.
  31.         "\t" . 'Capital'.
  32.         "\t" . 'Aquiring'.
  33.         "\t" . 'Expansion'.
  34.         "\t" . 'Funds'.
  35.         "\t" . 'Extraction'.
  36.         "\t" . 'Sale'.
  37.         "\t" . 'Generation'.
  38.         "\t" . 'Exiting'.
  39.         "\t" . 'Lifestlye' .
  40.         "\t" . 'Date' . "\n";
  41.  
  42. if ($result->num_rows > 0) {
  43.  
  44.     while($row = $result->fetch_assoc()) {
  45.  
  46.         $status         = $row["status"];
  47.         $firstname      = $row["field_id_27"];
  48.         $lastname       = $row["field_id_28"];
  49.         $email          = $row["field_id_3"];
  50.         $partner        = $row["field_id_5"];
  51.         $partner2       = $row["field_id_20"];
  52.         $date           = $row["entry_date"];
  53.         $formatted_date = gmdate("d/m/Y", $date);
  54.  
  55.         $topics         = $row["field_id_21"];
  56.  
  57.         //Reset all topics to nothing
  58.         $startup        = "";
  59.         $cashflow       = "";
  60.         $reliefs        = "";
  61.         $risks          = "";
  62.         $rewarding      = "";
  63.         $senior         = "";      
  64.         $capital        = "";      
  65.         $aquiring       = "";      
  66.         $expansion      = "";      
  67.         $funds          = "";      
  68.         $extraction     = "";      
  69.         $sale           = "";      
  70.         $generation     = "";              
  71.         $exiting        = "";
  72.         $lifestyle      = "";
  73.        
  74.         //If topic keyword exists in topics string, set to "Yes"
  75.         if (strpos($topics, "Startup")      !== false) { $startup       = "Yes"; }
  76.         if (strpos($topics, "Flow")         !== false) { $cashflow      = "Yes"; }
  77.         if (strpos($topics, "Reliefs")      !== false) { $reliefs       = "Yes"; }
  78.         if (strpos($topics, "risks")        !== false) { $risks         = "Yes"; }
  79.         if (strpos($topics, "Rewarding")    !== false) { $rewarding     = "Yes"; }
  80.         if (strpos($topics, "Senior")       !== false) { $senior        = "Yes"; }
  81.         if (strpos($topics, "Efficiently")  !== false) { $Capital       = "Yes"; }
  82.         if (strpos($topics, "Acquiring")    !== false) { $aquiring      = "Yes"; }
  83.         if (strpos($topics, "Expansion")    !== false) { $expansion     = "Yes"; }
  84.         if (strpos($topics, "Funds")        !== false) { $funds         = "Yes"; }
  85.         if (strpos($topics, "Extraction")   !== false) { $extraction    = "Yes"; }
  86.         if (strpos($topics, "Sale")         !== false) { $sale          = "Yes"; }
  87.         if (strpos($topics, "Generation")   !== false) { $generation    = "Yes"; }
  88.         if (strpos($topics, "Exiting")      !== false) { $exiting       = "Yes"; }
  89.         if (strpos($topics, "Lifestyle")    !== false) { $lifestyle     = "Yes"; }
  90.  
  91.         //Export the data to rows in the spreadsheet
  92.         echo   $status .
  93.         "\t" . $firstname .
  94.         "\t" . $lastname .
  95.         "\t" . $email .
  96.         "\t" . $partner . $partner2 .
  97.         "\t" . $startup .
  98.         "\t" . $cashflow .
  99.         "\t" . $reliefs .
  100.         "\t" . $risks .
  101.         "\t" . $rewarding .
  102.         "\t" . $senior .
  103.         "\t" . $capital .
  104.         "\t" . $aquiring .
  105.         "\t" . $expansion .
  106.         "\t" . $funds .
  107.         "\t" . $extraction .
  108.         "\t" . $sale .
  109.         "\t" . $generation .
  110.         "\t" . $exiting .
  111.         "\t" . $lifestyle .
  112.         "\t" . $formatted_date .  "\n";
  113.     }
  114.    
  115. } else {
  116.     echo "0 results";
  117. }
  118.  
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement