Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple table problem I hope !

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi

Could someone please tell me why the following code won't work I'm new to this and can't see the problem.
I'm trying to make one of the cells in my table a certain length as it has a capacity of 100 characters.The problem code is in bold.

echo '<table align="center" cellspacing="2" cellpadding="2">
<tr>
<td><b>Grind No</b></td>
<td><b>Exam</b></td>
<td><b>Subject</b></td>
<td><b>Level</b></td>
<td><b>County</b></td>
<td><b>Town/Region</b></td>
<td><b>Extra Location Details</b></td>
<td><b>Contact Name</b></td>
<td><b>Contact Number</b></td>
</tr>';
// Fetch and print all the records
while ($row = mysql_fetch_array($result,MYSQL_NUM))
{
echo "

<tr>
<td>FG$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
<td>$row[3]</td>
<td>$row[4]</td>
<td>$row[5]</td>
<td width=20>$row[6]</td>
<td>$row[7]</td>
<td>$row[8]</td>
</tr>\n";
Tks
 
You failed to tell us what exactly is the problem. Since we cannot see your end result, we can hardly help you. I assume that the column is wider than the 20px you specified. That is usually because you have a word (or anything without spaces) that take up more space than you assign. Table cells will always expand to fit the item. That is the most I can help you at this time.
 
<td width=100>$row[6]</td> ?


Zameer Abdulla
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
Yes you are correct the cell is expanding to accomodate the text even though i thought that I specified the width of the particular cell. Is this code nearer to the mark it still doesn't work but i am heading in the right direction.

echo '<table align="center" cellspacing="2" cellpadding="2" width="100%" border="1">

// Fetch and print all the records
while ($row = mysql_fetch_array($result,MYSQL_NUM))
{
echo "

<tr>
<td width='10%'>FG$row[0]</td>
<td width='10%'>$row[1]</td>
<td width='10%'>$row[2]</td>
<td width='10%'>$row[3]</td>
<td width='10%'>$row[4]</td>
<td width='10%'>$row[5]</td>
<td width='20%'>$row[6]</td>
<td width='10%'>$row[7]</td>
<td width='10%'>$row[8]</td>
</tr>\n";
 
No. Like I said, you cannot control how wide the cell will be if the content inside the cell has no spaces (or is an image). Just try typing a string without spaces in here and see what happens to the page -- it gets messed up. One thing for IE is to give it word-wrap: break-word; but as said, that is an IE only solution. For all browsers support you might use overflow: auto; property and have scrollbars appear in the cell if content is too long. To use the word-wrap for IE solution, change td to:
Code:
<td style="word-wrap: break-word; width="50em;">$row[6]</td>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top