Jump to content

[SOLVED] How to get dotted line between row, if used loop to get images


y2yang

Recommended Posts

Please help, I am new and will take any advice.

 

The bottom line is I wanted to get a dotted line in between my two rows of images.

 

The code that I used to achieve that line in hard coded is:

 

				<div style="clear:left;overflow:hidden;width:0;height:0;"></div>
		    <p style="margin:20px;"></p>
			<div class="dotHLine1"></div>
			<p style="margin:20px;"></p>

 

dotHLine is a class I defined in my css to get that dotted line.

 

The completed hard coded (which included the code above) to get the two rows of images is below, it may look long but the only thing changing is the LINK URL and IMAGE PATH.

 

	
        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=8"><img src="...thumb8.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=7"><img src="...thumb7.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=6"><img src="...thumb6.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=5"><img src="...thumb5.jpg"></a></td>
              </tr>
           </table>
</div>

// DOTTED LINE code/////////////////////////////////////

			<div style="clear:left;overflow:hidden;width:0;height:0;"></div>
		    <p style="margin:20px;"></p>
			<div class="dotHLine1"></div>
			<p style="margin:20px;"></p>

// DOTTED LINE code/////////////////////////////////////

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=4"><img src="...thumb4.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=3"><img src="...thumb3.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=2"><img src="...thumb2.jpg"></a></td>
              </tr>
           </table>
</div>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=1"><img src="...thumb1.jpg"></a></td>
              </tr>
           </table>
</div>

 

 

If I used loop to achieve that long code above, it will look like this, but without the dotted line code (and that's where my problem come in) since I can't have the dotted line to repeat after every image:

 

<?php
$query = "SELECT * FROM thumb LIMIT 0, 8";
$result =  mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
?>

        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=<?php print $row['id']; ?>"><img src="<?php print $row['imgpath']; ?>"></a></td>
              </tr>
           </table>
</div>	

<?php
}
?>

 

The loop will returned 8 images from my mysql row 1-8 to my HTML. The 8 images will fit into 2 rows on my page, with 4 images on top and 4 on bottom.

 

8 7 6 5

4 3 2 1

 

Now what I wanted to do is to have a dotted line in between my rows, like this:

 

8 7 6 5

---------

4 3 2 1

 

But as you can see, loop will put the images into my HTML like this:

 

8 7 6 5 4 3 2 1 ; without the dotted line.

 

What I wanted is to have something like if row = 4, then put my dotted line code after:

 

8 7 6 5 DOTTED LINE CODE 4 3 2 1

and my page will fit it into something like this:

 

8 7 6 5

--------

4 3 2 1

 

 

With all wish, I hope I make sense and may god help me.

 

 

Link to comment
Share on other sites

Why do you keep starting new topics? You had one perfectly fine for this. You do know that if you continued with your other topic, other people could have read up on what I did and what you wanted and could help you easier? Not to mention I already somewhat solved this problem in the other topic!

 

Also I think you got the numbers wrong.

 

It would be:

 

1 2 3 4

--------

5 6 7 8

 

<?php
$max_images = 8;

$query = "SELECT * FROM thumb LIMIT 0," . $max_images;
$result =  mysql_query($query);
$count = 0;
$half_point = (int) ($max_images / 2);
while ($row = mysql_fetch_assoc($result)) {
     if (!empty($count) && $count % $half_point == 0) {
?>
            <div style="clear:left;overflow:hidden;width:0;height:0;"></div>
             <p style="margin:20px;"></p>
            <div class="dotHLine1"></div>
            <p style="margin:20px;"></p>
<?php
    }
?>
        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=<?php print $row['id']; ?>"><img src="<?php print $row['imgpath']; ?>"></a></td>
              </tr>
           </table>
   </div>   

<?php
}
?>

Link to comment
Share on other sites

Thanks Ken2k7.

 

The code you gave me worked good.

 

But somehow I still not see the dotted line.

 

Can you double check the code?

 

Thanks.

 

<?php

$max_images = 8;

 

$query = "SELECT * FROM thumb LIMIT 0," . $max_images;

$result =  mysql_query($query);

$count = 0;

$half_point = (int) ($max_images / 2);

while ($row = mysql_fetch_assoc($result)) {

    if (!empty($count) && $count % $half_point == 0) {

?>

            <div style="clear:left;overflow:hidden;width:0;height:0;"></div>

            <p style="margin:20px;"></p>

            <div class="dotHLine1"></div>

            <p style="margin:20px;"></p>

<?php

    }

?>

        <div...>

          <table...>

              <tr...>

                <td><a href="...view.php?id=<?php print $row['id']; ?>"><img src="<?php print $row['imgpath']; ?>"></a></td>

              </tr>

          </table>

  </div> 

 

<?php

}

?>

Link to comment
Share on other sites

Oops, forgot to increment $count.

 

<?php
$max_images = 8;

$query = "SELECT * FROM thumb LIMIT 0," . $max_images;
$result =  mysql_query($query);
$count = 0;
$half_point = (int) ($max_images / 2);
while ($row = mysql_fetch_assoc($result)) {
     if (!empty($count) && $count % $half_point == 0) {
?>
            <div style="clear:left;overflow:hidden;width:0;height:0;"></div>
             <p style="margin:20px;"></p>
            <div class="dotHLine1"></div>
            <p style="margin:20px;"></p>
<?php
    }
    $count++;
?>
        <div...>
           <table...>
              <tr...>
                 <td><a href="...view.php?id=<?php print $row['id']; ?>"><img src="<?php print $row['imgpath']; ?>"></a></td>
              </tr>
           </table>
   </div>   

<?php
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.