Forum Moderators: coopster

Message Too Old, No Replies

PHP Table Cell Size Issue

Cannot control the cell size in a table

         

surfmore

10:52 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Hello,

I am creating a table and populating its cells with in a while loop. There are two queries involved and based on the value change of the first query, I go an get the data from the MySql table with the second query. My issue is when the tables get populated from the second table the cell sizes are different. How do I control the cell size the code is below.

Thank You

<?php
$sqlDistinct = "SELECT DISTINCT status from contracts ORDER BY Status";
if (!($resultstatus = @ mysql_query ($sqlDistinct, $connection)))
showerror();

while ($rowstatus = mysql_fetch_array($resultstatus, MYSQL_NUM))
{
$contractstatus = $rowstatus[0];
Print("CONTRACT STATUS: " . $contractstatus);
echo '<table width="115%" border="3" cellspacing="3" cellpadding="3">';
echo '<tr bgcolor="#666666">';
echo '<td width="6%"><font color="#CCFFFF">Contract Id</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Contract Number</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Vendor Number</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Vendor Name</font></td>';
echo '<td width="2%"><font color="#CCFFFF">Group Id</font></td>';
echo '<td width="2%"><font color="#CCFFFF">Category</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Specialist</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Start</font></td>';
echo '<td width="6%"><font color="#CCFFFF">Finish</font></td>';
echo '<td width="46%"><font color="#CCFFFF">Comment</font></td>';
echo '</tr>';

$sql = "SELECT contracts.vnumber, contracts.vname, contracts.groupid, contracts.category, ".
"contracts.specialist, contracts.start, contracts.finish, contracts.comment, contracts.contractid, contracts.contractnbr ".
"FROM contracts WHERE contracts.status='".$contractstatus."'";

if (!($result = @ mysql_query ($sql, $connection)))
showerror();
// (4) While there are still rows in the result set, fetch the current row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo '<tr bgcolor="#999999">';
//Format the numbers
$vnumber=$row[0];
$vname=$row[1];
$groupid=$row[2];
$category=$row[3];
$specialist=$row[4];
$start=$row[5];
$finish=$row[6];
$comment=$row[7];
$contractid=$row[8];
$contractnmb=$row[9];
echo "<td>$contractid</td>";
echo "<td>$contractnmb</td>";
echo "<td>$vnumber</td>";
echo "<td>$vname</td>";
echo "<td>$groupid</td>";
echo "<td>$category</td>";
echo "<td>$specialist</td>";
echo "<td>$start</td>";
echo "<td>$finish</td>";
echo "<td>$comment</td>";
}
echo "</table>";
}
?>

Timotheos

11:20 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi surfmore,

Maybe the problem is you don't have a </tr> for closing the rows?

Tim

surfmore

2:41 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Thanks for the reply and I added the /tr but it hod no effect.

Warboss Alex

2:52 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Try explicitely setting the cell widths in both query outputs.

ergophobe

5:41 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



At least with Firefox, your table will expand to whatever size it needs for the header cell. In other words, 6% will set a min width, but not a max. If you put, for example, an image in the cell that took 20% of screen width, that's what you would get.

In any case, this is really a job for CSS and a question for the HTML or CSS forums. What you need to do is get your layout to work on a static page. Then we can help you with how to generate that same code dynamically. First, though, you need code that works statically.

surfmore

5:20 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



Thanks for the reply.