?
Solved

PHP+MySQL and HTML tables

Posted on 2004-04-12
3
Medium Priority
?
267 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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