我有这段代码:
public function getAttendance($date, $name) {
$query = "SELECT CONVERT(db_obecnosci.attend USING utf8) FROM db_obecnosci WHERE attend_time = '".$date."' AND name = '".$name."'";
$result= $this->db->select($query);
if ($result == 'empty') {
return 'P';
}
elseif ($result == 'present') {
return 'O';
}
elseif ($result == 'apsent') {
return 'N';
}
elseif ($result == 'late') {
return 'S';
}
else {
return 'P';
}
}
我想要比较来自sql列的数据:参与字符串:空,现在,不存在和迟到。我做错了什么?请帮帮我。
public function select($query) {
$result = $this->link->query($query)
or die($this->link->error.__LINE__);
if ($result->num_rows > 0) {
return $result;
} else {
return false;
}
链接是sql对象
我改为:
public function getAttendance($date, $name) {
$query = "SELECT db_obecnosci.attend FROM db_obecnosci WHERE attend_time = '".$date."' AND name = '".$name."'";
$result= $this->db->select($query);
$row = mysqli_fetch_assoc($result);
if ($row["attend"] == 'empty') {
return 'P';
}
elseif ($row["attend"] == 'present') {
return 'O';
}
elseif ($row["attend"] == 'apsent') {
return 'N';
}
elseif ($row["attend"] == 'late') {
return 'S';
}
else {
return 'P';
}
}