title: Generate Excel File with specific group of output
body: <p>Can someone or somebody help me with my code or with my SQL execution? I'd like to create an excel file based on a specific group of data based on the event/activity they participated in.</p>
  <p>Here is my code:</p>
  <pre><code>$program_admin = $_SESSION['username'];
  $actvty_ID = $_POST['id'];
  //$activitydate = $_POST['activity_date'];
  
  if(isset($_POST['export_in_excel'])) {
      $excel_sql = &quot;SELECT *
                    FROM projectcode pj
                    INNER JOIN activities ac ON ac.projects_id = pj.projects_id
                    INNER JOIN participants re ON re.act_id = ac.id
                    WHERE pj.project_code='$program_admin'
                    ORDER BY re.id DESC &quot;; //pj.project_code='$program_admin'
     
      $excel_result = mysqli_query($connect, $excel_sql);
  
      if(mysqli_num_rows($excel_result) &gt; 0) {
          $excel_output .='
          &lt;table class=&quot;excel_table&quot; style=&quot;font-family:Calibri; border:1px solid #1f004d;&quot;&gt;
          &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d;&quot;&gt;No.&lt;/th&gt;
                  &lt;th colspan=&quot;2&quot; style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d;&quot;&gt;Name&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Age&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Gender&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;City/Municipality&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Province&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Contact No.&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Email Address&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Organization&lt;/th&gt;
                  &lt;th style=&quot;text-align:center; font-weight:bold; border:1px solid #1f004d; &quot;&gt;Signature&lt;/th&gt;
              &lt;/tr&gt;
          ';
          $no = 1;
          while($excel_row = mysqli_fetch_array($excel_result)) {
              $excel_output .='
                  &lt;tr&gt;
                      &lt;td style=&quot;text-align:center;&quot;&gt;'.$no.'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;firstname&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;lastname&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;agerange&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;gender&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;city_municipality&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;province&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;mobileno&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;email&quot;].'&lt;/td&gt;
                      &lt;td&gt;'.$excel_row[&quot;org_office&quot;].'&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      
                  &lt;/tr&gt;
              ';
              $no ++;
          }
          $excel_output .='&lt;/table&gt;';
          header(&quot;Content-Type: application/xls&quot;);
          header(&quot;Content-Disposition: attachment; filename=Attendance Sheet.xls&quot;);
          echo $excel_output;
          
      }
  }
  </code></pre>
  <p>And here is the sample output of my code:
  <a href="https://i.stack.imgur.com/sAXgS.png" rel="nofollow noreferrer">enter image description here</a></p>