title: PHP/mySQL Export to CSV but ONLY user selected date range data
body: <p>i'm stumped and could use some much appreciated help figuring this out.</p>
  
  <p>basically, i've got a page that displays data from a mysql database.</p>
  
  <p>i have a simple text link to export all the data to a CSV file that downloads.
  that code is...</p>
  
  <pre><code>&lt;a href="log_activity-export2CSV.php?id=&lt;?php echo $colname_CoachActivityListData ?&gt;"&gt;Export All&lt;/a&gt;
  </code></pre>
  
  <p>...this works just fine.</p>
  
  <p>note: everything is generated based on the user that's logged in - thus the need for the ID.</p>
  
  <p>here is the content/code of the PHP file that exports the above to CSV...</p>
  
  <pre><code>&lt;?php 
  mysql_select_db($database_vandyConnect, $vandyConnect);
  
  $queryString = "SELECT Created, Last_Updated, coach_name, Start_Date, End_Date, And_Many_More_Columns FROM Activity_Log WHERE User_id = ". $_GET['id'];
  
  $result = mysql_query($queryString, $vandyConnect);
  
  // $result = $db_con-&gt;query('SELECT * FROM `Activity_Log`');
  if (!$result) die('Couldn\'t fetch records');
  
  $num_fields = mysql_num_fields($result);
  
  $headers = array();
  for ($i = 0; $i &lt; $num_fields; $i++) {
      $headers[] = mysql_field_name($result , $i);
  }
  
  // $today = date("F_j,_Y,_g:ia");
  $today = date("Ymd_g-ia");
  
  $fp = fopen('php://output', 'w');
  if ($fp &amp;&amp; $result) {
      header('Content-Type: text/csv');
      header('Content-Disposition: attachment; filename="ADEC_Activty_export-'.($today).'.csv"');
      header('Pragma: no-cache');
      header('Expires: 0');
      fputcsv($fp, $headers);
      while ($row = mysql_fetch_row($result)){
          fputcsv($fp, $row, ",");
      }
      die;
  }
  ?&gt;
  </code></pre>
  
  <p>...note: i stripped out all the php code from above this that Dreamweaver inserted for me that connects it to the database and user permissions etc.</p>
  
  <p><strong>SO NOW</strong>, i'm trying to figure out how to add a way for the user to download a CSV file of this data but <em>ONLY</em> between certain date ranges that the user picks out.</p>
  
  <p>to begin, i chose to use the JQuery DatePicker that i've used elsewhere in the site, but this time to use its DateRange option...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt; //to pick date range
  $(function() {
      $( "#from_start" ).datepicker({
          defaultDate: "-2m",
          changeMonth: true,
          numberOfMonths: 2,
          onSelect: function( selectedDate ) {
              $( "#to_end" ).datepicker( "option", "minDate", selectedDate );
          }
      });
      $( "#to_end" ).datepicker({
          defaultDate: "-1m",
          changeMonth: true,
          numberOfMonths: 2,
          onSelect: function( selectedDate ) {
              $( "#from_start" ).datepicker( "option", "maxDate", selectedDate );
          }
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>...note: this part works fine too.
  then i made the html form for the user to select their date range...</p>
  
  <pre><code>&lt;form method="POST" action="log_activity-export2CSV.php?id=&lt;?php echo $colname_CoachActivityListData ?&gt;"&gt;
      Select a date range from &lt;input type="text" id="from_start" name="from_start" value="" /&gt; to &lt;input type="text" id="to_end" name="to_end" value="" /&gt;
      &lt;input name="export" type="submit" value="Export CSV" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>...i gave the "action" the same as the above "export all link",
  and here's the kicker/crux of this whole question -
  i can't figure out how to push the selected values of the form to the CSV export, so that what downloads is only between the selected date range.</p>
  
  <p>if anybody can guide me, i'd appreciate it.
  also note: tho this is a lot of code, i am a total noob with php, so please be gentle ;-)
  THANKS,
  -jason.</p>