turpentyne Posted July 27, 2012 Share Posted July 27, 2012 Ok.. I know. probably a really simple thing, but I'm not sure how I should do this. I have a query at the top of my page that pulls data from mysql. Then I want to generate the page and have the data populate specific divs in the page, based on which category the data is. (I'll also want to control this, so that if they select one options, it redoes the query to pull more specific data for the other divs. But I should stick to one thing at a time) It's looping through the whole page code right now. I understand what's happening, but I'm just not sure how to create the page once, do the query once, and just loop through the data (unless I shouldn't do it) Here's what I have right now... <?php include("dbc.php"); $query_barrel_options = "SELECT component_name, image_filepath, category_ID FROM tbl_components"; $result = mysql_query($query_barrel_options); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <!--html code--> <div id="1"> <?php echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; ?> </div> <div id="11"> <?php if ($row[category_ID]=="11") { echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; } ?> </div> <div id="1"> <?php if ($row[category_ID]=="12") { echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; } ?> </div> <!--rest of html --> <?php } ?> </body> </html> <? Quote Link to comment https://forums.phpfreaks.com/topic/266350-using-while-loop-in-specific-places/ Share on other sites More sharing options...
ManiacDan Posted August 23, 2012 Share Posted August 23, 2012 Are you looking for something other than "Move the HTML code outside the while loop"? Quote Link to comment https://forums.phpfreaks.com/topic/266350-using-while-loop-in-specific-places/#findComment-1371789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.