Jump to content

[SOLVED] Little Help Please


paulman888888

Recommended Posts

Hi guys;

Ill get straight to the point!

 

I am trying to use the DATE function but i don't now how to use it will Mysql.

 

Ill explain;

 

Am trying to use a PHP to get results from Mysql where the date is before today.

 

I would like to say thankyou in advance.

Paul

Link to comment
https://forums.phpfreaks.com/topic/134229-solved-little-help-please/
Share on other sites

Mysql has a lot of built in date and time functions that can be used to do just about anything you want and they execute much faster than any slow parsed/tokenized/interpreted php code -

 

$query = "SELECT * FROM table WHERE date_field < CURDATE()";

I tryed but for some reason it wont work.

 

Heres my code

 

<?php
error_reporting(E_ALL);
include'connection_1.php';
$strr = $_GET['only'];
$strr = strtolower($strr);
$allowedonly = array('upcoming', 'events');
if(isset($_GET['only'])){
if(in_array($strr,$allowedonly)){
if($strr='upcoming'){$opp='>';}
elseif($strr='past'){$opp='<';}
$sort="WHERE date_field ".$opp." '".date("Y-m-d")."'"; 
}else{$error='Search Not Found';$sort='';}}else{$sort='';}
  $result = mysql_query("SELECT * FROM chess_events '$sort'"); 
?>

and i get error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/site/events.php on line 46

 

thankyou

for all the help!

Paul

 

I think your code is unnecessarily complicated.  What about simplifying?

 

<?php
error_reporting(E_ALL);

include'connection_1.php';

$query = "SELECT * FROM chess_events";
if (isset($_GET['only']))
{
if ($_GET['only'] == 'upcoming')
{
	$query .= " WHERE date_field > CURDATE()"; 
}
elseif ($_GET['only'] == 'past')
{
	$query .= " WHERE date_field < CURDATE()";
}
}
$result = mysql_query($query); 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.