1

I'm trying to display each specific image to display in PHP/HTML page, it's currently displaying all the pages but I would like it to only display one for whenever I type in the function.

My code:

 <div class="ser-grid-list img_style">
                            <div class="gallery1">


                            </div>
                        </div>
                        <div class="ser-grid-list img_style">
                            <div class="gallery1">

                            </div>
                        </div>
                        <div class="ser-grid-list img_style">
                            <div class="gallery1">

                            </div>
                        </div>
                        <div class="ser-grid-list img_style">
                            <div class="gallery1">
                                                            <?php
 $sql = "SELECT image FROM product"; //sql query
 $result = mysql_query($sql) or die(mysql_error($connection));
 while ($row = mysql_fetch_array($result)) //display the results
 {
 echo "<p><img src='../images/" . ($row['image']) . "'" . " " . " />"; 
 }

?>

What its doing:

http://puu.sh/cCs29/6769667d43.jpg

What I'm wanting to make them do is align from left to right. It was working with Static images coming through html but I decided to use a database. This was it prior

http://puu.sh/cCs5g/919c0c8c57.jpg

Thanks!

1
  • Please care about the fact that mysql_* functions are deprecated. You should use PDO instead, there are many tutorials to learn how to use this. If your PHP version is recent enough and errors are on and E_ALL, your script will generate a E_DEPRECATED error. Commented Nov 4, 2014 at 3:05

2 Answers 2

3

Simply get the id of your image just like this one

 $sql = "SELECT image FROM product where id=101";

This is the easiest one? Am i missing something?

Sign up to request clarification or add additional context in comments.

1 Comment

CodeSlayer, you're a life saver! :)
2

<p> is a block element, so it'll start and end with a new line. If you want to display them inline, try eliminating the <p> tags surrounding the <img> tags.

And as @CodeSlayer suggests, if you only want one single image returned, add a WHERE clause to your query to fetch a specific image.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.