如下判断无效(当res不为空是echo1,反之echo res1),该如何修改?
<?php
header('content-type:application/json');
//$id= $_GET['id'];
//$name= $_GET['name'];
$id= '1223';
$name= 'LILY';
// 连接数据库
require '../connect/pdo_connect_db.php';
$res = $pdo->query("SELECT * FROM (
SELECT a.subject,a.type,b.teacher FROM table1 a
LEFT JOIN table2 b ON a.subject= b.subject WHERE a.subject
= (SELECT subject FROM table3 WHERE id ='$id' ORDER BY operation_time DESC LIMIT 1)
)y WHERE name= '$name'")->fetchall(PDO::FETCH_ASSOC);
$res1 = $pdo->query("SELECT a.subject,a.type,b.teacher FROM table1 a
LEFT JOIN table2 b ON a.subject= b.subjectWHERE a.subject
= (SELECT subject FROM table3 WHERE id='$id' ORDER BY operation_time DESC LIMIT 1)")->fetchall(PDO::FETCH_ASSOC);
if($res) {
echo "1";
} else{
echo json_encode($res1);
}