mysql - How to return a COUNT(*) results from a query PHP -
public function votesthismonth() { $this->query = $this->pdo->prepare (" select count(*) num_votes votes year(year) = year(current_date) , month(month) = month(current_date) "); $result = $this->query->execute(); return $result['num_votes']; }
i want return rows on year 2013 , month 5. returns '1' while have 10+ rows same data?
what did wrong?
these rows located in database:
id ip year month 1 127.0.0.1 2013 5 2 127.0.0.1 2013 5 3 127.0.0.1 2013 5 4 127.0.0.1 2013 5 5 127.0.0.1 2013 5 6 127.0.0.1 2013 5 7 127.0.0.1 2013 5 8 127.0.0.1 2013 5 9 127.0.0.1 2013 5 10 127.0.0.1 2013 5 11 127.0.0.1 2013 5 12 127.0.0.1 2013 5 13 127.0.0.1 2013 5 14 127.0.0.1 2013 5 15 127.0.0.1 2013 5
edited method please look:
public function votesthismonth() { $this->query = $this->pdo->prepare (" select * votes year(year) = year(current_date) , month(month) = month(current_date) "); $this->query->execute(); return $this->query->rowcount(); }
this returns '0', why?
the query should
select * votes `year` = year(current_date) , `month` = month(current_date)
Comments
Post a Comment