0

I am just getting started in using PHP and MySQL for a project.

I want to create the following query using pseudonyms for the tables involved in the query.

$query1 = "SELECT Q.NAME
           FROM QUALIFICATION Q, STUDENT S, HAS H
           WHERE S.ID=$ID AND S.ID=H.STUDENT_ID AND H.QUALIF_NAME = Q.NAME";

$result1 = mysqli_query($con, $query1); 

while($rows = mysqli_fetch_array($result1)){
    $QNAME = $rows1['Q.NAME'];... 

However I am getting the error:

Notice: Undefined index: Q.NAME

Probably I am missing something terribly wrong in the syntax, so any help would be really valuable!

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
Alice1nw0
  • 69
  • 1
  • 10
  • Oops, looks like our edits collided, and we each changed what the other didn't so it's wrong again. Sorry about that! – Don't Panic Jan 23 '18 at 23:53

1 Answers1

0

Use $rows['NAME'] rather than $rows['Q.NAME']. The table part of the identifier won't be included in the result.

(Leave it as Q.NAME in the SQL query, though. Just change it in the array key.)

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • The $rows was indeed a typo. I've tried using $rows['NAME'] but NAME is also a column at the STUDENT table. – Alice1nw0 Jan 23 '18 at 23:46
  • That shouldn't matter at the PHP level. You are only selecting that one column in your query. You _do_ have to use `Q.NAME` in the SQL to disambiguate that column, but in PHP array it won't appear as `Q.NAME`, just `NAME`. – Don't Panic Jan 23 '18 at 23:50