Solved

PHP+MySQL and HTML tables

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now