While loops objects next to each other

Fadi946

Power Member
Joined
Mar 25, 2009
Messages
621
Reaction score
93
Hey guys so I'm trying to make a list of books in my website (getting them from my database), and I succeded to put them but they are displaying one under the other... and I want to put them side by side.

Just in case you didn't understand me, I will give you an example:

What I have now is:
Book1
Book2
book3

What I want to do is:
Book1 -> Book2 -> Book3

This is my code:

PHP:
               include 'DBConnection.php';            
$ShowTopic = 'SELECT * FROM Books WHERE age = "Children"';      
      $Topicquery = mysql_query($ShowTopic);      
      while($DisTopic=mysql_fetch_array($Topicquery)){     
       ?>       
    <div class="new_products">         
           <div class="new_prod_box">         
               <a href="details.php?book=<?php echo $DisTopic['getTitle']?>"><?php echo $DisTopic['Title'];?></a>   
                     <div class="new_prod_bg1">         
                <a href="details.php?book=<?php echo $DisTopic['getTitle']?>"><img src="<?php echo $DisTopic['Image'];?>" alt="" width="98" height="150" title="" class="thumb" border="0" /></a>   
                     </div>                   
            </div>                  
               </div>      
       <?php       
     }     
   ?>

I've tested many way to do it, and I noticed that the problem is the "while".. because without it, it will be good... but I really need this while loop.

Anyone can help me please? Its for my final project and I will gladly appreciate your help :)
Thanks!

-Fadi
 
Try this

<?php
include 'DBConnection.php';
$Topicquery = mysql_query('SELECT * FROM Books WHERE age = "Children"');
if(mysql_num_rows($Topicquery) > 0){
while($DisTopic=mysql_fetch_assoc($Topicquery)){
?>

<div class="new_products">
<div class="new_prod_box">
<a href="details.php?book=<?php echo $DisTopic['getTitle']; ?>"><?php echo $DisTopic['Title']; ?></a>
<div class="new_prod_bg1">
<a href="details.php?book=<?php echo $DisTopic['getTitle']; ?>"><img src="<?php echo $DisTopic['Image']; ?>" alt="" width="98" height="150" title="" class="thumb" border="0" /></a>
</div>
</div>
</div>
<?php
}
}
?>
 
Thanks for answering, but it did not really work :( Still the same problem.
 
What error message do you get, what kiind of problem is it?

EDIT: sorry didnt read good, i'll tryu to fix it now.
 
Last edited:
Would you please make the code a bit more readable? Can't see it actually n havin to copy it to my editor:P
 
not tested. Let me know if this works
Code:
<?


               include 'DBConnection.php';            
$ShowTopic = 'SELECT * FROM Books WHERE age = "Children"';      
      $Topicquery = mysql_query($ShowTopic);      
      ?>
	  <div class="new_products">  
	  <?
	  while($DisTopic=mysql_fetch_array($Topicquery)){     
       ?>       
           
           <div class="new_prod_box">         
               <a href="details.php?book=<?php echo $DisTopic['getTitle']?>"><?php echo $DisTopic['Title'];?></a>   
                     <div class="new_prod_bg1">         
                <a href="details.php?book=<?php echo $DisTopic['getTitle']?>"><img src="<?php echo $DisTopic['Image'];?>" alt="" width="98" height="150" title="" class="thumb" border="0" /></a>   
                     </div>                   
            </div>                  
                   
       <?php       
     }     
   ?>
   <div style="clear:both"></div>
   </div>  
   
   <style> .new_prod_box{float:left;width:250px; height:100px; display:block;}</style>
 
use css :)

<div class="bookthumbnail">...bookstuff</div>

.bookthumbnail{
width: 33%;
float: left;
}
 
Last edited:
Thanks so much g0g0l!!! I've been trying to fix it for so long, and now it works!! You're awesome! +rep!
(Thanks to everyone who tried to help as well! Much appreciated!)
 
Thanks budd :-)
Thanks so much g0g0l!!! I've been trying to fix it for so long, and now it works!! You're awesome! +rep!
(Thanks to everyone who tried to help as well! Much appreciated!)
 
Back
Top