I have a query which pulls a count from a DB by searching by date and it’s not returning what it should. There’s 3 records in the database, type Date, with the date 2012-04-06.
$day is echoing out on the page as that date, so I know it’s passing into the function right.
$countrows = "SELECT COUNT(*) FROM test_table WHERE startDate LIKE '" . $day. "'";
$countresult = mysql_query($countrows);
$count = mysql_fetch_row($countresult);
$finalcount = $count[0];
Just stuck, need a second, third, fourth set of eyes. I’m obviously missing something.
ALSO: I’d like the count to come out as an integer so I can do math with it.
You’re missing the step of
$values = mysql_fetch_row($countresult). Your$countresultis a variable of typeMYSQL_QUERYRESULT(or somesuch) rather than an array.http://php.net/manual/en/function.mysql-fetch-row.php
Apart from that, DB queried values will always be strings first in PHP. just do a
$var = (int)$var;if you want to make sure it’s a number.