Forum Moderators: coopster

Message Too Old, No Replies

Controlling table layout in php

         

dave1236

6:54 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



I have the following code...that provides horrible table layout. I wnat to have a header for each column but cannot line up this info with the data that is pulled from the DB...any thoughts would be appreciated!

There are multiple rows for each user, so I so not know how to reconcile this with a specific table format.

<?php
echo "<table cellspacing='10'>";
echo "<tr><td colspan='5'><hr></td></tr>";
extract($row);
echo "<html>

<body>
<h2 align='top' style='margin-top: .0in'>
Welcome $firstName $lastName</h2>\n";

echo "Transaction history for $logname ";

echo "<tr>
User ID / Date / Item / Sale amount / Credit </tr>";


while ($row = mysql_fetch_array($result))
{
extract($row);
echo "
<tr>\n
<td>$logname</td>\n
<td>$date</td>\n
<td>$item</td>\n
<td>$$amount</td>\n
<td>$credit</td>\n
}
?>

barns101

7:19 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



It's best to design the table and get it working with test text first and then add the PHP later. For instance, you seem to be starting the table before your <html> and <body> tags.

eelixduppy

11:25 pm on Oct 4, 2006 (gmt 0)



Try something like this:

<html>
<body>
<?php
echo "<h2 align='center'>Welcome $firstName $lastName</h2>\n";
echo "Transaction history for $logname<br />";
?>
<table cellspacing='10px'>
<tr><td colspan='5' style="border-bottom: 1px solid #000000">&nbsp;</td></tr>
<tr>
<td>User ID</td>
<td>Date</td>
<td>Item</td>
<td>Sale amount</td>
<td>Credit</td>
</tr>
<?php
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "
<tr>\n
<td>$logname</td>\n
<td>$date</td>\n
<td>$item</td>\n
<td>$$amount</td>\n
<td>$credit</td>\n
</tr>";
}
?>
</table>

Good luck!

dave1236

1:07 am on Oct 7, 2006 (gmt 0)

10+ Year Member



Thanks! I see how this will work!