Error when accessing MySQL table columns

Hi,
MySQL has a table called images. This table has 4 columns named as ID, title, subtitle, image.
I want to connect to this table as print all information in the title column. I tried this:

<?php
require "../app/core/database.php";
$sql = "SELECT ID FROM images";
$result = $connection->query($sql);
while($row = $result->fetch_assoc())
{
    echo $row['title'];
}
$connection->close();
?>

But, the output says Undefined array key ‘title’ in …
Please guide me.

You didn’t SELECT the title column.

2 Likes

Thanks,
Considering the following html code can put image in the page, how can I loop through all rows of the image column and load images into the page? (image column has both file name and its extension)

<div class="full-screen-portfolio" id="portfolio">

        <div class="container-fluid">

            <div class="col-md-4 col-sm-6">

                <div class="portfolio-item">

                    <a href="../public/assets/img/6087208979_601e4d9931_b.jpg" data-lightbox="image-1"><div class="thumb">

                        <div class="hover-effect">

                            <div class="hover-content">

                                <h1>Biodiesel <em>squid</em></h1>

                                <p>Awesome Subtittle Goes Here</p>

                            </div>

                        </div>

                        <div class="image">

                            <img src="../public/assets/img/6087208979_601e4d9931_b.jpg">

                        </div>

                    </div></a>

                </div>

            </div>

        </div>

    </div>

Well, you combine the top post with the last post. Inside the loop you would need to echo the HTML code for the image. Instead of just putting the img tags, or title, you would need to echo all of the portolio-item code. All tags for each item list. The While loop gets you your ID, but, you would need to select more, you would need the title, ID and image name. Subtitles whatever. The only thing you need to be careful of is how you echo your quotes and double-quotes. Make sense?

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service