While loops objects next to each other

 

Results 1 to 12 of 12
Hey guys so I'm trying to make a list of books in my website (getting ...
  1. #1
    Fadi946's Avatar
    Fadi946 is offline Regular Member
    Join Date
    Mar 2009
    Location
    With my parents :(
    Posts
    486
    Thanks
    223
    Thanked 69 Times in 44 Posts

    Default While loops objects next to each other

    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 Code:

                   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




  2. #2
    Kilise's Avatar
    Kilise is offline Newbies
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default Re: While loops objects next to each other

    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
    }
    }
    ?>

  3. The Following User Says Thank You to Kilise For This Useful Post:

    Fadi946 (01-27-2013)

  4. #3
    Fadi946's Avatar
    Fadi946 is offline Regular Member
    Join Date
    Mar 2009
    Location
    With my parents :(
    Posts
    486
    Thanks
    223
    Thanked 69 Times in 44 Posts

    Default Re: While loops objects next to each other

    Thanks for answering, but it did not really work Still the same problem.

  5. #4
    Kilise's Avatar
    Kilise is offline Newbies
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default Re: While loops objects next to each other

    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 by Kilise; 01-27-2013 at 05:29 PM.

  6. #5
    g0g0l is offline bit.ly/5wpsetup
    Join Date
    Sep 2010
    Posts
    2,526
    Thanks
    4,261
    Thanked 2,319 Times in 1,238 Posts
    Blog Entries
    3

    Default Re: While loops objects next to each other

    Would you please make the code a bit more readable? Can't see it actually n havin to copy it to my editor:P

  7. #6
    Kilise's Avatar
    Kilise is offline Newbies
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default Re: While loops objects next to each other

    You have to work with the css. The style. Try to float the divs left

  8. The Following User Says Thank You to Kilise For This Useful Post:

    Fadi946 (01-27-2013)

  9. #7
    g0g0l is offline bit.ly/5wpsetup
    Join Date
    Sep 2010
    Posts
    2,526
    Thanks
    4,261
    Thanked 2,319 Times in 1,238 Posts
    Blog Entries
    3

    Default Re: While loops objects next to each other

    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>

  10. The Following User Says Thank You to g0g0l For This Useful Post:

    Fadi946 (01-27-2013)

  11. #8
    0_00_0's Avatar
    0_00_0 is offline Jr. VIP
    Join Date
    Oct 2010
    Location
    Canada
    Posts
    981
    Thanks
    30
    Thanked 424 Times in 296 Posts

    Default Re: While loops objects next to each other

    use css

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

    .bookthumbnail{
    width: 33%;
    float: left;
    }
    Last edited by 0_00_0; 01-27-2013 at 05:38 PM.

  12. The Following User Says Thank You to 0_00_0 For This Useful Post:

    Fadi946 (01-27-2013)

  13. #9
    Fadi946's Avatar
    Fadi946 is offline Regular Member
    Join Date
    Mar 2009
    Location
    With my parents :(
    Posts
    486
    Thanks
    223
    Thanked 69 Times in 44 Posts

    Default Re: While loops objects next to each other

    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!)

  14. #10
    g0g0l is offline bit.ly/5wpsetup
    Join Date
    Sep 2010
    Posts
    2,526
    Thanks
    4,261
    Thanked 2,319 Times in 1,238 Posts
    Blog Entries
    3

    Default Re: While loops objects next to each other

    Thanks budd :-)
    Quote Originally Posted by Fadi946 View Post
    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!)

  15. #11
    gabmasm's Avatar
    gabmasm is offline Registered Member
    Join Date
    Feb 2012
    Posts
    60
    Thanks
    125
    Thanked 26 Times in 21 Posts

    Default Re: While loops objects next to each other

    float left or using a table tag?

  16. #12
    Fadi946's Avatar
    Fadi946 is offline Regular Member
    Join Date
    Mar 2009
    Location
    With my parents :(
    Posts
    486
    Thanks
    223
    Thanked 69 Times in 44 Posts

    Default Re: While loops objects next to each other

    Quote Originally Posted by gabmasm View Post
    float left or using a table tag?
    putting the "while" AFTER the "new_product" div solved it.


Similar Threads

  1. Looking for an Expert WebDesigner (Need Movable Objects)
    By howard_hughes in forum Hire a Freelancer
    Replies: 1
    Last Post: 07-31-2012, 06:16 PM
  2. Weird objects in photo's taken from nasa satellite
    By ghengis_khan in forum BlackHat Lounge
    Replies: 3
    Last Post: 11-20-2011, 09:20 PM
  3. BHCB Showing up behind flash objects
    By rubberband in forum Black Hat SEO Tools
    Replies: 2
    Last Post: 11-24-2009, 10:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108