I’m trying to write an INNER JOIN query. I wanted to get rows/information that are in two different tables. Here’s what I’m trying:
Table Names are: Students and main_table
$sql =mysql_query ("SELECT main_table.maric_no, main_table.academic_session, main_table.semester,
main_table.course_name, main_table.total, students.first_name, students.last_name,
students.other_name, students.level
FROM main_table INNER JOIN students ON
main_table.matric_no = students.matric_no
WHERE main_table.matric = mysql_real_escape_string($_POST[matric_no]'");
$number_cols = mysql_num_fields($sql);
Here’s the error message:
ERROR: mysql_num_fields() expects parameter 1 to be resource, boolean given in c:\filepath on line Number..
Where could the problem be coming from?
Two errors at first glance:
Format it like this:
I took the liberty to add aliases to the table names, this cleans up your SQL statement quite a lot.
There might be other errors, too (p.e. wrong fields, is your WHERE-statement really on the field
main_table.matricand notmain_table.matric_no?), but in order to analyze this you’ll need to provide more details about your tables.