0

hey guys im trying to query something in php but the WHERE is a index from array this is what i did

    $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);

but unfortunately i got an error in $check_archive_subjects that says:

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'

is there any other way to put an array index in where clause in mysql. I know mysql is deprecated and ill be switching to mysqli after i finished this project so pardon me guys. thanks in advance

0

2 Answers 2

4

Multiple WHERE conditions should be joined using boolean keywords AND or OR. You don't issue multiple WHERE clauses.

Also, please read this regarding the MySQL extension - https://stackoverflow.com/a/12860046/283366

Sign up to request clarification or add additional context in comments.

1 Comment

oh!!.. silly me.. i thought it was the array. thanks! BTW i have read about that. Im still using mysql bcuz this is what our professors thought to us and lately i found out that its already deprecated when we already started this project.
0

Try the below query

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

Explanation

Using multiple WHERE clause like above is not accepted in MySQL. Try replacing the 2nd WHERE using an AND or using an OR depending on your requirement. I have used AND

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.