Comments:		
		
			The form itself includes a call to the fmExecuteSQL function, using a static SELECT statement 
			to generate the list of the states referenced in the database. 
			
			It also makes use of FMWebFrame's caching function. If available, the list of states
			is pulled from the cache.
*/
// Initialize the request.
require_once dirname(__FILE__) . '/../FMWebFrame/FMWebFrame.php';
// Check to see if there is a list of states in the cache.
$states_cache = fmCacheGet('states');
// If there is no cached list of states, or the cache is more than 30 days old...
if ($states_cache === null or $states_cache['Cache_Age'] > 60 * 60 * 24 * 30) {
    // Get a list of the states that are referenced in the Contacts table.
    $states = fmExecuteSQL($fmDemo, 'SELECT DISTINCT State FROM Contacts ORDER BY State');
    // Cache the list.
    fmCachePut($states, 'states');
} else {
    // Get the content of the cache.
    $states = $states_cache['Cache_Contents'];
}
// Set page title.
$ui_title = "FMWebFrame Demo | ExecuteSQL";
// Start output buffering.
ob_start();
?>

<h1>ExecuteSQL</h1>

<p>With FMWebFrame's "fmExecuteSQL" function, you can query FileMaker databases using SQL Select statements directly from your Web solutions. The SELECT statements can be static (like the one used to generate the list of states in the form below) or dynamically generated (based on user criteria).</p>
}
if ($_GET['last_name'] !== '') {
    if ($_GET['first_name'] !== '') {
        $query .= ' AND';
    }
    $query .= ' Last_Name LIKE \'' . fmSubstitute($_GET['last_name'], '\'', '\'\'') . '%\'';
}
if ($_GET['state'] !== '') {
    if ($_GET['first_name'] !== '' or $_GET['last_name'] !== '') {
        $query .= ' AND';
    }
    $query .= ' State = \'' . fmSubstitute($_GET['state'], '\'', '\'\'') . '\'';
}
$query .= ' ORDER BY Last_Name, First_Name';
// Execute the query.
$contacts = fmExecuteSQL($fmDemo, $query);
// Set page title.
$ui_title = "FMWebFrame Demo | ExecuteSQL";
// Start output buffering.
ob_start();
// Page header.
echo '<h1>ExecuteSQL</h1>';
// If there was a problem with the query...
if ($contacts == '?') {
    echo '<p>Oops! An unexpected error occurred.</p>';
    echo '<p><a href="executesql-form.php">Click here</a> to try again.</p>';
} elseif ($contacts == '') {
    echo '<p>Sorry, but no contacts were found that meet your criteria.</p>';
    echo '<p><a href="executesql-form.php">Click here</a> to try again.</p>';
} else {
    // Display the number of contacts returned.
		
			2014-01-14	Tim Dietrich
				Initial version.	
				
		Comments:		
			None.
*/
// Initialize the request.
require_once dirname(__FILE__) . '/../FMWebFrame/FMWebFrame.php';
// Get the start time.
$current_time = microtime();
$current_time = explode(' ', $current_time);
$current_time = $current_time[1] + $current_time[0];
$page_start_time = $current_time;
// Get a list of the states that are referenced in the Contacts table.
$state_counts = fmExecuteSQL($fmDemo, 'SELECT State, COUNT(*) FROM Contacts GROUP BY State ORDER BY State');
// Get the stop time.
$current_time = microtime();
$current_time = explode(' ', $current_time);
$current_time = $current_time[1] + $current_time[0];
$page_stop_time = $current_time;
// Get the elapsed time.
$page_elapsed_time = round($page_stop_time - $page_start_time, 4);
// Get a unique ID for this example.
$uuid = uniqid();
// Cache the results.
fmCachePut($state_counts, 'state_counts_' . $uuid);
// Set page title.
$ui_title = "FMWebFrame Demo | Caching";
// Start output buffering.
ob_start();