OK so I would like to get a match for a query of the database using a LIKE operator in my SQL statement.
I'm looking at a field that has a date and time in it, like this
2012-04-27 12:00:00
I only want to compare the first part of the string, just the date bit, so I was using LIKE but I don't get any matches.
Here's the code
$colname_cruises = "-1";
if (isset($_GET['id'])) {
$colname_cruises = str_replace('-', ' ', $_GET['id']);
}
$colname_date = "-1";
if (isset($_GET['date'])) {
$colname_date = $_GET['date'];
}
$query_cruises = sprintf("SELECT * FROM cruises WHERE title = %s AND departs LIKE %s", GetSQLValueString($colname_cruises, "text"), GetSQLValueString($colname_date, "text"));
$cruises = mysql_query($query_cruises, $connection) or die(mysql_error());
$row_cruises = mysql_fetch_assoc($cruises);
$totalRows_cruises = mysql_num_rows($cruises);
I'm pretty certain just doing a LIKE %s isn't enough... what else can I add in here ?
LIKE %%%s%%which will be translated to%your_date%by sprintf and will mean "your_date maybe prefixed by something and maybe followed by something". You may have to tweak a little depending on wether your GetSQLValueString function adds quotes ...