Hello, I am having a problem with extracting records from the db and displaying them correctly. Currently in the database I have 20 or so records. The database structure is like this: image_id|image_path|title|description|status|category I have data which I want to get from the database and put into the relevant boxes on the page depending on what category they are in. They need to go in this code: Code: <div class="middle_box_toplong">Title 1</div> <div class="center_boxlong"> <div align="left"> <img src="<?php echo $path; ?>" width="50" height="50" /> </div> </div> Code (markup): I want all the images from category 1 to be displayed with a box titled "1" like this: Code: <div class="middle_box_toplong">1</div> <div class="center_boxlong"> <div align="left"> <img src="<?php echo $path; ?>" width="50" height="50" /> <img src="<?php echo $path; ?>" width="50" height="50" /> <img src="<?php echo $path; ?>" width="50" height="50" /> <img src="<?php echo $path; ?>" width="50" height="50" /> <img src="<?php echo $path; ?>" width="50" height="50" /> </div> </div> Code (markup): This will obviously be in a while loop. But there are more than one category to get from the database. The problem I am having at the moment is that it is making a new box for every single image coming from the database, when i just want it to add the image into the relevant box. Sorry for my poor description, it is difficult to explain. Let me know if you do not understand. Thanks
If I am understanding you correctly......it sounds like you need the code for your box (the <div>s) to be outside of your while statement....then have the while statement display only the images. For instance.........Create a function to display the images in a separate file (functions.php). Then on your html or php page (include functions.php at the top) then inside your box...call that function. Once called it will display your images.
Thats what I thought, but if I did that it would just be one big box. When I need separate boxes for different categories. Edit: Oh my goodness how could I forget the wonderful where statement in SQL. I think I can consider this solved now.
yep you can do different functions for different categories or make one big function like function getimagesbycategory("$category") { that accepts the name of your category to put in your SQL where command }