0

嘿伙计们,我试图在 php 中查询一些东西,但是 WHERE 是数组中的一个索引,这就是我所做的

    $data=array();
                    while ($row = mysql_fetch_array($result))
                                {
                                    $item = array(
                                       'sec_id'=>$row['section_id'],
                                       'sec_name'=>$row['section_name'],
                                       'sec_dept'=>$row['section_department'],
                                       'sec_lvl'=>$row['section_level'],
                                      'advisory_id'=>$row['advisory_id'],
                                      'first_name'=>$row['f_firstname'],
                                      'last_name'=>$row['f_lastname'],
                                      'middle_name'=>$row['f_middlename'],
                                      'advisor_id'=>$row['faculty_id'],
                                    );


                    $get_subjects = "SELECT subject_name
                                        FROM subjects  
                                        WHERE level = '".$row['section_level']."' ";


                        $result_get_subjects =mysql_query($get_subjects)or die(mysql_error());

                        $subjects_count = mysql_num_rows($result_get_subjects);


                    $check_archive_subjects = " SELECT b.subject_name 
                                                FROM registrar_grade_archive a
                                                LEFT JOIN subjects b ON(a.subject_id=b.subject_id)
                                                LEFT JOIN section c ON(a.section_id = c.section_id)                                                 
                                                WHERE a.advisor_faculty_id ='".$row['faculty_id']."'
                                                WHERE a.section_id ='".$row['section_id']."'

                                                GROUP BY b.subject_name ASC
                                                 " ;

                     $query_checking =mysql_query($check_archive_subjects)or die(mysql_error());

                    $subjects_count_sent = mysql_num_rows($query_checking);

但不幸的是,我在 $check_archive_subjects 中遇到了一个错误,上面写着:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE a.section_id ='24'

有没有其他方法可以将数组索引放在 mysql 的 where 子句中。我知道 mysql 已被弃用,并且在我完成这个项目后将切换到 mysqli,所以请原谅我。提前致谢

4

2 回答 2

4

多个WHERE条件应使用布尔关键字ANDOR. 您不会发出多个WHERE条款。

另外,请阅读有关 MySQL 扩展的内容 - https://stackoverflow.com/a/12860046/283366

于 2013-01-27T06:08:12.700 回答
0

试试下面的查询

SELECT b.subject_name
FROM registrar_grade_archive a
LEFT JOIN subjects b ON(a.subject_id=b.subject_id)
LEFT JOIN section c ON(a.section_id = c.section_id)
WHERE a.advisor_faculty_id ='".$row['faculty_id']."' AND a.section_id ='".$row['section_id']."'
GROUP BY b.subject_name ASC

解释

WHEREMySQL 不接受使用像上面这样的多个子句。根据您的要求,尝试WHERE使用AND或使用替换第二个。OR我用过AND

于 2013-01-27T06:16:21.917 回答