0

I am currently having problem using the mysql query to search the number of rows that match the particular month and then the function returns back the number of rows here is my code:

public function getAllChart($reading, $month){
    $stmt = $this->con->prepare("SELECT ? FROM garden WHERE ? IS NOT NULL AND MONTH(STR_TO_DATE(time, '%e-%b-%Y')) = ?");
    $stmt->bind_param("ssi",$reading,$reading,$month);
    $stmt->execute();
    $stmt->store_result();
    $num_rows = $stmt->num_rows;
    $stmt->close();
    return $num_rows;
}

the above function if i pass getallchart(temp,4) then it should show only those columns that are not null and match the month also, it behaves abnormally like if i use:

$stmt = $this->con->prepare("SELECT ? FROM garden WHERE ? !=''");
        $stmt->bind_param("ss",$reading,$reading);

then it doesn't work but when i use :

$stmt = $this->con->prepare("SELECT temp FROM garden WHERE temp !=''");

then it works but i don't know what's the problem as i need different parameters as per function.

. can anyone help.

rahul kapoor
  • 51
  • 3
  • 10

0 Answers0