How to print my $row3 in a same line

I have the following code and the while loop is working but it is looping through each picture on a new line. I would like to put all the pictures on the same line side by side and not sure if this is a css side or my php side. I tried to include inline-block in my css code but can’t get it to work with my div class of image:

while($row2 = mysqli_fetch_assoc($result2)) {
                               $sql3 = "SELECT * FROM pictures WHERE name = ?;";
                         $stmt = mysqli_stmt_init($conn);
                    if(!mysqli_stmt_prepare($stmt, $sql3)) {
                       echo "SQL error";
                    } else {
                      mysqli_stmt_bind_param($stmt, "s", $row2['clinic_name']);
                      $result3 = mysqli_stmt_get_result($stmt);
                     echo '<tr><th>Clinic NO:</th><td>'.$rowNumber.'</td></tr>
                     <tr><th>Clinic Name:</th><td>'.$row2['clinic_name'].'</td></tr>
                           <tr><th>Clinic Address:</th><td>'.$row2['clinic_address'].'</td></tr>
                           <tr><th>Clinic Number:</th><td>'.$row2['clinic_number'].'</td></tr>
                           <tr><th>Which of the following are you?</th><td>'.$row2['type_of_profession'].'</td></tr>
                           <tr><th>Recommended Doctors:</th><td>'.$row2['doctors'].'</td></tr>';
                            while($row3 = mysqli_fetch_assoc($result3)) {
                           echo '<tr><th>Pictures:</th><td><img src='.$row3['pictures'].' class="image"></td></tr>';

Try echoing the last </tr> after your while loop has finished.

The way it is currently written is creating a new table row for each picture. Try this:

echo '<tr><th>Pictures:</th>';

while($row3 = mysqli_fetch_assoc($result3)) {

                           echo <td><img src='.$row3['pictures'].' class="image"></td>';


echo '</tr>';

I will correct the code for you, seen that there are parsing errors on your code:

echo '<tr><th>Pictures:</th>';

while($row3 = mysqli_fetch_assoc($result3)) {

                           echo '<td><img src="'.$row3['pictures'].'" class="image"></td>';


echo '</tr>';

That almost did the trick but then in my css, how would I reduce the big gap between pictures?

I tried to use float:left but that didn’t help

you want it looks like this?

I would like the magnifying glass to be closer to the stethoscope

you’d use position: absolute; z-index: 5 and use the magnifying inside the table?

A simple method that might work considering that its html formatting where the problem is … the tr and td tags. Use something like front page to make a table as you like it with sample images to give you the proper code for a table and html tags, look at code source … and then place your php directives where your sample image code is to display the images you want in the proper place…the problem is in your table code structure … where to put the tr and td tags …

At a glance your css is showing a larger table with two smaller columns inside and one with rows … to have the glass closer put it in the same table as the stethoscope …then you can adjust space… in a different table, all you can do is float it left as far as it will go to the border of the table. In the same table one image can be float left and the other center and both be closer together… option two is do float right on the stethoscope and left on the glass… then they are both on the right border and closer together.

So i guess that I must have a separate class for each picture?

asking a thing! (i cannot imagine good)

you want a thing similar to this?

you’d use this if it is:

echo '<tr><th>Pictures:</th></tr><td><table><tbody><tr>';

while($row3 = mysqli_fetch_assoc($result3)) {

                           echo '<td><img src="'.$row3['pictures'].'" class="image"></td><td>magnifying glass</td>';


echo '</tr></tbody></table></td>';
1 Like

I am confused here because I already have a table class…

i mean you can use tables inside tables to stylize pictures

1 Like

I didn’t know that you can use another table within the same table, is this an okay structure to use?

i also use similar to it and works ok. so yes

Now, it doesn’t look right… :neutral_face:

The other code was better…

wait where did you put it :confused: ? i fixed the top code

i mean. you should use mine instead of very top one

I got it with this code! I just had to place the td tags outside the loop!

     echo '<tr><th>Pictures:</th><td>';
                                    while($row3 = mysqli_fetch_assoc($result3)) {
                                      //  echo '<td><table><tbody><tr><td><img src="'.$row3['pictures'].'" class="image"></td><td>magnifying glass</td></tr></tbody></table></td>';

                                   echo '<img src="'.$row3['pictures'].'" class="image">';
                               echo '</tr></td>';`Preformatted text`
1 Like

I guess we all learn new things everytime!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.