Pulling MySQL data from query

$sql = 'SELECT users.NAME, company.name
FROM users
LEFT JOIN (user_company_access, company) ON (users.USER_ID=user_company_access.company_id AND user_company_access.company_id=company.company_id)
WHERE users.USER_ID="1" AND company.company_id=users.USER_ID';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "USER ID :"+$row[0]+"  <br> ";
} 

I am getting:

Notice: Undefined offset: 0 in C:xampphtdocsindex.php on line 23
0
Notice: Undefined offset: 0 in C:xampphtdocsindex.php on line 23
0Fetched data successfully

Is there a way to directly pull the data? I tried doing something like $row[‘users.NAME’] as well but still failed.


Source: php

Leave a Reply