-1

I want to match contact from both tables and fetch details of mother in mysql using JOIN clause in php.

Table students

name mother mcontact
Larry Wanda 12345678

Table parents

name parent_of relation contact other
Wanda Larry mother 12345678 any other details

And this is my code

$user_query = 'SELECT students.mcontact FROM `students` JOIN `parents` ON students.mcontact=parents.contact';
$user_result = mysqli_query($db_conn, $user_query);

while ($users = mysqli_fetch_object($user_result)){

  echo $users->name}

It is showing me an error Undefined property $name

If there is any other way to do it please enlighten me.

2 Answers2

0

Also, as Lawrence mentioned abouve, adding the students.name to the sql query like so.

$user_query = 'SELECT students.mcontact, students.name FROM `students` JOIN `parents` ON students.mcontact=parents.contact';
bmckay
  • 19
  • 1
  • 4
0
$user_query = 'SELECT students.mcontact,students.name,parents.name as parentName FROM `students` JOIN `parents` ON students.mcontact=parents.contact';
$user_result = mysqli_query($db_conn, $user_query);