0

I have a dynamically generated DIV

<div class="content drag-desired">
<?php
  $result = mysql_query("SELECT * FROM XXXX WHERE qty != 0");
while($row=mysql_fetch_assoc($result))
{
echo '<div class="product"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" />
<div>'.$row['price'].'$</div></div>';
}
 ?>
 <div class="clear"></div>
 </div>

the while loop makes the list be very long,

Any idea how to make the div contains 6 items only and show the fetched items 6 by 6?

I don't know the logic behind the scene. :)

I will be appreciated, if someone explain the follow chart for making the div slides.

Thanks

Rhyme Free
  • 25
  • 6

1 Answers1

1

Like so:

<div class="content drag-desired">
<?php
  $result = mysql_query("SELECT * FROM XXXX WHERE qty != 0");
  $counter = 0;
  while($row=mysql_fetch_assoc($result))
  {
  if($counter==0)
    echo '<div class="slide">';

    echo '<div class="product"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" />
    <div>'.$row['price'].'$</div></div>';

  if($counter==5)
    echo '<div>';

  $counter++;
  if($counter > 5)
    $counter = 0;
  }
  ?>
  <div class="clear"></div>
  </div>

So, the code below counts to 6 and wraps 6 items inside "slide". I think you understand the logic I used :) And with a little hint of CSS/JavaScript you can make your own slider that changes slide to be shown.

Karri Rasinmäki
  • 1,019
  • 10
  • 19