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
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.