Solved

PHP+MySQL and HTML tables

Posted on 2004-04-12
3
239 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

776 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