0

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.

2 Answers 2

1

You're missing the step of $values = mysql_fetch_row($countresult). Your $countresult is a variable of type MYSQL_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.

Sign up to request clarification or add additional context in comments.

6 Comments

Updating original to show the real field name of startDate instead.
It just echoes out 'array' now
Updated question to have the fetch row as well.
$finalcount echoes 'array'? That would be strange since DB values are never arrays.
Yeah I know. I'm really confused.
|
1

You shouldn't use LIKE for date comparisons. You can just do

"SELECT COUNT(*) FROM test_table WHERE startDate = '" . $day. "'";

And as Armatus points out, you need to call mysql_fetch_row as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.