0
$stfeeres = mysql_query("SELECT * FROM student INNER JOIN stledger ON student.stid = stledger.stid WHERE student.status='Active' AND date('m-Y', strtotime(stledger.entrytime))=date('m-Y')");

I am trying get month and year. entrytime is timestamp in table. Please help me.

I am getting error

Warning: mysql_fetch_array() expects parameter 1 to be resource

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
  • Possible duplicate of [mysqli\_fetch\_array()/mysqli\_fetch\_assoc()/mysqli\_fetch\_row() expects parameter 1 to be resource or mysqli\_result, boolean given](https://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1) – Progman Sep 11 '17 at 08:16

2 Answers2

0

Try it so:

SELECT * FROM `student` WHERE MONTH(entrytime)=MONTH('2017-08-18') AND YEAR(entrytime)=YEAR('2017-08-18')

Than the mysql will look for the month "08" and the year "2017".

EDIT:

$yourDate='2017-08-18'; // or date('Y-m-d');

$stfeeres = mysql_query("SELECT `stledger`.entrytime FROM student INNER JOIN stledger ON student.stid = stledger.stid WHERE student.status='Active'
AND MONTH(stledger.entrytime)=MONTH({$yourDate})
AND YEAR(stledger.entrytime)=YEAR({$yourDate})");

And do not use mysql_* use instead mysqli_*.

Richard
  • 618
  • 1
  • 9
  • 15
0

$m=date('m-Y'); mysql_query("SELECT * FROM student INNER JOIN stledger ON student.stid = stledger.stid WHERE student.status='Active' AND DATE_FORMAT(stledger.entrydate, '%m-%Y')='$m'");

I got the result from this. :)