-1

I want to display data from different columns into my html page.

<?php

require '../../config.php';

$connection = new mysqli($servername, $username, $password, $db);

$query = "SELECT * FROM Empresa WHERE id='3'";
$result = $connection->query($query); 
?>

<div class="col-md-6">
           <h3> <?php
               while ($row = mysqli_fetch_array($result)) {
                echo $row["name"]; }
                ?> </h3>
            <br>
            <p><?php
                while($row = mysqli_fetch_array($result)) {
                 echo $row["description"];}
                    ?></p>
        </div>

On the first instance it works fine no matter what column I call but after the first loop it never displays anything again.

Thanks in advance!

0

1 Answer 1

0

Instead of doing this, you can do with single loop :

<div class="col-md-6">
    <?php
        while ($row = mysqli_fetch_array($result)) {
            echo "<h3>".$row["nombre"]."</h3>";
            echo "<p>".$row["description"]."</p>";
        }
        result -> free();
    ?>
</div>
Sign up to request clarification or add additional context in comments.

9 Comments

ok that works! but what if i want to display more data outside this div? can i only get one loop to work?
More data means. If data is of the same row, then sure, you can initiate the loop outside of the <div>.
If this answer solved your problem then you should mark it as the selected answer for this question. And you can while loop any were to get any amount of data for the selected table. If you want to call some thing from another table which is not in the selected on then you need to use JOIN.
@$errano Glad it help. Waiting for the green sign
Downwote for what ???
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.