I've read through the topic on using Max's script to create a CSV download and it works a treat in it's base form. I am trying to add a WHERE clause, drawing a value from a dropdown, to the SQL SELECT which gets the table rows for output. The column I'm matching `event_date` on will contain a text string.
In the form HTML code box I've this:-
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">
Select Show to Download as a CSV file</label>
<select class="cf_inputbox required"
id="event_date" size="1" title="You must choose a show." name="event_date">
<option value="">Choose a Show...</option>
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `event_date`
FROM `jos_chronoforms_KCShowEntries`
;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
echo "<option value=\"".$o[event_date]."\">".$o[event_date]."</option>";
}
?>
</select>
</div>
<div class="cfclear">ย </div>
</div>
<div class="form_item">
<div class="form_element cf_button">
<input class="art-button" value="Download" name="submit" id="submit"
type="submit" />
</div>
<div class="cfclear">ย </div>
</div>
And in the OnSubmit after email:
<?php
if ( !$mainframe->isSite() ) { return; }
$where_clause = JRequest::getVar('event_date');
global $mainframe;
$database =& JFactory::getDBO();
include_once JPATH_BASE.'/components/com_chronocontact/excelwriter/'."Writer.php";
//echo $_POST['formid'];
/*$formid = JRequest::getVar( 'formid', array(), 'post', 'array');
$database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" );
$formname = $database->loadResult();*/
$tablename = 'jos_chronoforms_KCShowEntries';
$tables = array( $tablename );
$result = $database->getTableFields( $tables );
$table_fields = array_keys($result[$tablename]);
$database->setQuery( "SELECT * FROM ".$tablename." WHERE `event_date` = " '$where_clause');
$datarows = $database->loadObjectList();
$titcol = 0;
foreach($table_fields as $table_field){
if($titcol){$csvline .=",";}
$csvline .= $table_field;
$titcol++;
}
$csvline .="\n";
*********
etc etc etc as original
?>
Sorry to be a pain and thanks in advance for any help.
Nick