Jump to content

need help finding item by date (mysql)


lunac

Recommended Posts

Hi,

I'm trying to pass some values into a calendar I'm making. I have the calendar itself working fine, now I'm trying to put the event titles on to it. But I'm have problems getting items for a particular date. My date field is a timestamp in mysql.

 

Any help would be appreciated.

 

here's my code:

 

 

$e = mysqlSelect($_tables['squirrel_post'], "post_slug, title, date", "WHERE  date =  $date");

 

if I take the date out -- it works, but then I'm getting all the post rather than just the post of that day. Also, I know that it's passing the date as 2008-7-6 -- which isn't right either.

 

 

by the way.. here's the code for my mysqlSelect function --- which is complete function (lol)

function mysqlSelect($from, $what="*", $conditions=""){
		$query = "SELECT $what from $from $conditions";
		$r = lib_executeQuery($query) or die(mysql_error());
		return $r;
}
function lib_executeQuery($query,$dbLink=""){
        // Execute an SQL query passed to this function
        if($dbLink){
        	$link = $dbLink;
        } else {
        	$link = lib_databaseConnect();
        }
        $dbResult = mysql_query($query, $link)
            or die ("Database Class: MySQL Error: " . mysql_error() );
        return $dbResult;
    }

Link to comment
https://forums.phpfreaks.com/topic/116515-need-help-finding-item-by-date-mysql/
Share on other sites

HAHAHA

 

That was exactly the problem --  the date was entering into the query wrong, so I caught it on the front end.

 

SOLUTION:

	$gm = strlen($month);
	$month =($gm == 1)? "0" . $month : $month;
	$currentDay =($gm == 1)? "0" . $currentDay : $currentDay;
	$date = "$year-$month-$currentDay";
	$e = mysqlSelect($_tables['squirrel_post'], "*", "WHERE  date= '" . $date . "'");  

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.