php - 如果 where 等于数组索引,则在 php mysql 中选择 where

标签 php mysql arrays

嘿伙计们我想在 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,所以请原谅我。提前致谢

最佳答案

多个 WHERE 条件应该使用 bool 关键字 ANDOR 连接。您不会发出多个 WHERE 子句。

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

关于php - 如果 where 等于数组索引,则在 php mysql 中选择 where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14544922/

相关文章:

php - 为下拉列表取另一个表值

php - 未定义数量的有效负载参数 - RESTful

php - 保护 GET 请求的好方法?

php - Symfony2 Timestable 特征 : "Column ' createdAt' cannot be null"

mysql - 将对象与特定日期正确关联(SQL & Rails 4)

c - 将数组内的十六进制值显示到标准输出,并将输入与这些十六进制值进行比较

mysql - 计数连接中的重复列名

mysql - 为什么我的 SQL 存储过程在没有结果时给出错误?

javascript - 绑定(bind)类 - 数组的项目

arrays - 隐式类适用于所有 Traversable 子类,包括 Array