Search code examples
phpmysqlinner-join

PHP display $rows from inner table


Like on title... how to display row data from inner join table if name of the row are the same?? but data is diffrent?

$sql = "SELECT fv.name,fvcount.name,fvcount.datew,fvcount.u_uid 
        FROM fv 
        INNER JOIN fvcount ON fv.u_uid = fvcount.u_uid ";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
   echo $row['u_uid'];
 }

Result will be printed, but on both table 1 of the rows name is like: name

So if i put

$row['name'];

i will have output of inner join table

How to get output from main table and inner joint table? I can't change name of the row...

Any clue?


Solution

  • The typical solution is to use column aliases. You can do something like:

    SELECT fv.name AS fv_name, fvcount.name as fvcount_name, ...
    

    And then use:

    $row['fv_name']
    

    Or:

    $row['fvcount_name']