Solved

Styling HTML Table output from MySQL Query Results

Posted on 2011-09-23
2
295 Views
Last Modified: 2012-05-12
I am attempting to create a report that will output the transactions for all clients in my database. I'm having a hard time getting the layout right, though. I need a space between the last row of the data table and the next client table header row.

I haven't started styling this yet, so please be kind - it's terribly ugly. If you have any suggestions on that front, please include them!

Here's what I have now:
Report Table
And here's my code:
<?php
include('config.php');
$account = ''; // Declare Account to Empty

$sql = "SELECT * from client, billing WHERE client.id = billing.client ORDER BY client.id DESC";
$result = mysql_query($sql) or die(mysql_error());

// Keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)){
   if ($row['account'] != $account) { // check if new account
        $account = $row['account'];
        if ($cnt > 0) echo '</tr>'; // check if open table row
        $cnt = 0; // set $cnt to zero and echo table row for new account
        echo "<table border='1' width='800px' align='center'><th>Client ID</th><th>First Name</th><th>Last Name</th><th>Case Style</th><th>Accident Date</th><th>SOL Expires</th>";
        echo "<tr><td>";
        echo $row['account'];
        echo "</td><td>";
        echo $row['fname'];
        echo "</td><td>";
        echo $row['lname'];
        echo "</td><td>";
        echo $row['casestyle'];
        echo "</td><td>";
        echo $row['accidentdate'];
        echo "</td><td>";
        echo $row['solexpires'];
        echo "</td></tr></table>";
        echo "<br /><table border='1' width='800px' align='center'>";
        echo "<tr><th>Date</th><th>Client ID</th><th>Transaction Type</th><th>Charge</th><th>Billed From</th><th>Payment</th></tr>";
        }
        if ($cnt == 0) echo '<tr>';
        // Print out the contents of each row into a table
        echo "<td>";
        echo $row['date'];
        echo "</td><td>";
        echo $row['account'];
        echo "</td><td>";
        echo $row['job_type'];
        echo "</td><td>";
        echo $row['charge'];
        echo "</td><td>";
        echo $row['job_type'];
        echo "</td><td>";
        echo $row['payment'];
        echo "</td></tr>";
        $cnt++;
}

echo "</table>";
?>

Open in new window


Thanks in advance for your help.
0
Comment
Question by:goodie069
[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
2 Comments
 
LVL 3

Accepted Solution

by:
nrbreen earned 500 total points
ID: 36590520

You appear to be missing the /table after each data section

Change

        if ($cnt > 0) echo '</tr>'; // check if open table row

Open in new window


To

        if ($cnt > 0)  { echo '</tr></table><br />'; } // check if open table row

Open in new window

0
 

Author Comment

by:goodie069
ID: 36590577
Ugh, I knew it was something glaringly obvious. Thank you!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

726 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