I have a database with a table which includes among others, one column of dates (the column is titled 'date') in the format of Y-m-d.
I want to extract all the rows of data which have been logged during the current month, so I am using the following query:
$year_month = date("Y-m");
$query = "SELECT date FROM tracker WHERE date LIKE '$year_month%'";
When I execute the query and attempt to output it visually, I get the error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 64".
Line 64 is the beginning of the following loop:
while($row = mysql_fetch_array($result, MYSQL_ASSOC)
{
echo "Name :{$row['date']} <br>";
}
I've scoured google and had a look here too, but I can't seem to figure out this seemingly simple problem. As far as I can tell, the actual query is executing just fine.
Any ideas?
** Additional - Call to MySQL Query Below **
$result = mysqli_query($conn, $query);
$conn refers to the following line:
$conn = @mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Error connecting to MySQL');
What is the data type for the date field, if it is date type, then you should try following :
should be
date is a reserved word in sql.
look for more examples here
Two things jump out at me:
Are you sure that's the query that goes with that result? Queries like
insert
anddelete
do not have results. They return a boolean indicating success.Are you checking to make sure the query succeeded? After the line where you call
mysql_query
, make sure you check the result. If it's false, you can callmysql_get_error
to find out what went wrong.EDIT: Okay, your real problem is that you're mixing
mysql_*
andmysqli_*
commands. You need to use one or the other.Something like this should work nicely...
If you don't understand the error that you're getting from
mysql_error()
andmysql_errorno()
, then post the output and we should be able to help with it.