show query result

1

I need to show a query in a database in a table of two columns in html. I've done it that way, but it does not work out:

<table border=1>
    <tr>
        <th>Nombre</th>
        <th>Poblacion</th>
    </tr>
    <?php
        $sql3='SELECT city.Name,city.Population FROM city as city INNER JOIN country AS country ON city.CountryCode=country.Code
            WHERE (country.Region="'.$region.'") AND (country.Name="'.$name.'")';
        $resultado3=$db->query($sql3);
        echo $region;
        echo $name;
        echo "<br>";
        while($row=$resultado3->fetch(PDO::FETCH_ASSOC)){
            print_r ($row);
            echo "<br>";
            //echo '<tr><td>'.$row[0].'</td><td>'.$row[1].'</td></tr>';
        }
    ?>
    </table>

This appears to me, but I do not want it this way:

  

Array ([Name] = > Oranjestad [Population] = > 29034)

    
asked by Charly Utrilla 24.12.2018 в 17:31
source

1 answer

1

You need to access the names of the columns like this:

<table border=1>
<tr>
    <th>Nombre</th>
    <th>Poblacion</th>
</tr>
<?php
    $sql3='SELECT city.Name,city.Population FROM city as city INNER JOIN country AS country ON city.CountryCode=country.Code
        WHERE (country.Region="'.$region.'") AND (country.Name="'.$name.'")';
    $resultado3=$db->query($sql3);
    echo $region;
    echo $name;

    while($row=$resultado3->fetch(PDO::FETCH_ASSOC)){
        echo "<tr>";
        echo "<td>" .  $row['Name'] . "</td>";
        echo "<td>" .  $row['Population'] . "</td>";
        echo "</tr>";           
    }
?>
</table>
    
answered by 24.12.2018 / 18:04
source