Solved

PHP+MySQL and HTML tables

Posted on 2004-04-12
3
252 Views
Last Modified: 2006-11-17
Hello Experts!

I want to create a nice looking table formatted output for this script.

Here's a working script with simple output only:
<?
if($category_db = $db->get_results("select distinct CategoryName from Parts"))
{
   foreach($category_db as $category)
   {
      // SET CATEGORY TITLE
      echo "<B>" . $category->CategoryName . "</B><BR>";

      // LOOP THE PARTS DB
      if($part_db = $db->get_results("SELECT PartName from Parts where
CategoryName='$category->CategoryName'"))
      {
         foreach($part_db as $part)
         {
            // LIST THE PARTS FOR THIS CATEGORY
            echo $part->PartName . "<BR>";
         }
      } else { // DO SOMETHING }                
   }
} else { // DO SOMETHING }

?>

It should be able to adapt hundreds of records and will have a clean table format.  An example output maybe 20 Category Names and 10 0r more Part Names under each Category Name.

Thanks in advance!
:-)
0
Comment
Question by:nyerky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 125 total points
ID: 10805161
try this....

<?
if($category_db = $db->get_results("select distinct CategoryName from Parts"))
{
      print "<table>";
   foreach($category_db as $category)
   {
      // SET CATEGORY TITLE
      echo "<thead><th></tr>" . $category->CategoryName . "</tr></th></thead>";
        echo "<tbody> <tr>";
      // LOOP THE PARTS DB
      if($part_db = $db->get_results("SELECT PartName from Parts where CategoryName='$category->CategoryName'"))
      {
         foreach($part_db as $part)
         {
            // LIST THE PARTS FOR THIS CATEGORY
            echo "<td>".$part->PartName . "</td>";
         }
      } else { // DO SOMETHING }                
        echo "</tr></tbody>";
   }
      print "</table>";
} else { // DO SOMETHING }

?>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question