0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I have :

$connector = new DBconnector();

    $sql = "SELECT school.name, student-.ClassSize_7, student-.ClassSize_8, degree_o.degree_code, accredit.full_faculty_3,
    accredit.total_faculty_3, accredit.pc_terminal, accredit.stud_fac_ratio, fresh_en.num_appl_offered, fresh_en.num_appl_received FROM school
    INNER JOIN student- ON school.scid = student-.scid
    INNER JOIN degree_o ON school.scid = degree_o.scid
    INNER JOIN accredit ON school.scid = accredit.scid
    INNER JOIN fresh_en ON school.scid = fresh_en.scid
    ORDER BY school.name ASC LIMIT 0, 25";

    $result = $connector->query($sql);
    //$numberRows = $connector->numRows($result);
    $numRows = mysql_num_fields($result);

And my query isn't returning any results and I get a warning like this :

Warning: mysql_num_fields() expects parameter 1 to be resource, boolean given in C:\wamp\www\...\academics.php on line 17

and

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\...\academics.php on line 96

I don't know why, can anyone help me

Community
  • 1
  • 1
Wolf87
  • 546
  • 3
  • 11
  • 29
  • There's something wrong with your query. Try running it in phpmyadmin (if you have it available). – OptimusCrime Jun 25 '12 at 10:52
  • 2
    Wild guess: MySQL is complaining about the table name "student-". – Frank Schmitt Jun 25 '12 at 10:53
  • what do you expect from this code? why do you not using the commented line //$numberRows = $connector->numRows($result); – khaled_webdev Jun 25 '12 at 10:56
  • What does your `DBConnector` do? `mysql_num_fields` requires the database ressource as parameter, so if your class' query method does not return that as result it surely fails. – enricog Jun 25 '12 at 10:57
  • 1
    Look on [`Manual`](http://php.net/manual/en/function.mysql-num-fields.php) Suggested alternatives : Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: – diEcho Jun 25 '12 at 10:57
  • Yes, I run in phpmyadmin and I got this error: #1064 - 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 ' student-.ClassSize_8, degree_o.degree_code, accredit.full_faculty_3, accredit.' at line 1 – Wolf87 Jun 25 '12 at 10:57
  • Try escaping all table and field names with backticks ` – Nick Jun 25 '12 at 11:02
  • @Frank Schmitt So what I can do, is it because of table name with '-'? – Wolf87 Jun 25 '12 at 11:02
  • 2
    `student-`? What kind of table name is this? – Salman A Jun 25 '12 at 11:08

2 Answers2

2

wrap your all columns with backticks ` like

 `student-`.`ClassSize_8`

because of - is in your column name

Suggestion : Change you table name from student- to student

diEcho
  • 52,196
  • 40
  • 166
  • 239
0

you need to complete from list

 $sql = "... fresh_en.num_appl_received FROM school,student-, degree_o,accredit ,fresh_en 
INNER JOIN ...";
khaled_webdev
  • 1,400
  • 14
  • 19