hi there,
I have a sort of CMS that allows you to simply chose a date range and it will echo out the all the results or just one result by selecting an option button.
I now need to add an additional clause that will all me to filter the results by country and between 2 dates.
here is what i have at the moment.
Can anyone please help me with this?
SQL Query
[php]
function getselectedfeeds(){
header('Content-type: text/plain; Charset=utf-8');
echo "<br /><h3>Entries</h3>";
$fmonth = $_POST['fmonth'];
$fday = $_POST['fday'];
$fhour = $_POST['fhour'];
$fmin = $_POST['fmin'];
$tmonth = $_POST['tmonth'];
$tday = $_POST['tday'];
$thour = $_POST['thour'];
$tmin = $_POST['tmin'];
$site = $_POST['site'];
$getwinner = $_POST['winner'];
$source = $_POST['source'];
$query = “SELECT * FROM competition WHERE site = ‘$site’ AND created > '2011-”.$fmonth."-".$fday." “.$fhour.”:".$fmin.":00’ AND created < ‘2011-".$tmonth."-".$tday." “.$thour.”:".$tmin.":00’ ";
if($getwinner)
{
$query .= “ORDER BY RAND() LIMIT 1”;
}
else
{
$query .= “ORDER BY created DESC”;
}
/*
id
fname
lname
email
number
optin
vote
competition
created
ip
site
*/
$results = db_list($query);
$results = $results[1];
if(!empty($results)){
echo '<h4>Total Results: '.count($results).'</h4>';
echo '<table width="100%">';
echo '<thead><tr><td>NAME</td><td>EMAIL</td><td>OPTIN</td><td>ANSWER</td><td>CREATED</td><td>SITE</td></tr></thead>';
$x=0;
foreach($results as $result){
if($x%2==0){$bg = '#f4f4f4;';}else{$bg = '#ffffff;';}
echo '<tr style="background: '.$bg.'">';
// name
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['first_name'])).' '.utf8_encode(html_entity_decode($result['last_name'])).'</td>';
// email
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['email'])).'</td>';
// contact optin
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['contact_me'])).'</td>';
// answer
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['answer'])).'</td>';
// created
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['created'])).'</td>';
// site //
echo '<td width="100%">'.utf8_encode(html_entity_decode($result['site'])).'</td>';
echo '</tr>';
$x++;
}
echo '</table>';
}else{
echo "No Records.";
}
}
[/php]
extra parameter to get results for england / Ireland
[php]
function getSources(){
echo 'Select Country:';
echo '<select id ="select_site name" name ="site">';
echo '<option value="england"';
if ($site == "england"){
echo " selected";
}
echo '> england</option>';
echo '<option value="ireland"';
else if ($site == "ireland") {
echo "selected";
echo ' > ireland</option>';
echo '</select><br />';
}
}[/php]