Jump to content

using while loop in specific places


turpentyne

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/266350-using-while-loop-in-specific-places/
Share on other sites

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.