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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for setting column width

Status
Not open for further replies.

mondeoman

MIS
Dec 7, 2006
203
0
0
GB
Hopefully this is a fairly simple question. I have a page that shows a table that derives its data from an MySQL db. I want to be able to vary the column widths individually but I am have trouble getting the right syntax. Can anyone show me how to change the width say of the column Event? The code for this part of the page is:

$table = "<form method=post><table border=\"1\" cellspacing=\"10\" body bgcolor=\"#AABBCC\" Align=Center>\n";
$tableHead = "<tr>
<th>Event</th>
<th>Start Time</th>
<th>End Time</th>
<th>Date</th>
<th>Member</th>
<th>Financial Year
<select name='year' onchange='form.submit();'>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select>
</th>
</tr>\n";

$tableHead = str_replace("<option>$year</option>","<option selected>$year</option>",$tableHead);

while($row = mysql_fetch_array($result)){

$tablerow .= "<tr>
<td>".$row['EventName']."</td>
<td>".$row['StartTime']."</td>
<td>".$row['EndTime']."</td>
<td>".$row['EventDate']."</td>
<td>".$row['Member']."</td>
<td>".$row['financialyear']."</td>
</tr>\n";

}
$tableEnd = "</table></form>\n";
?>
 
All you do is set the width for any cell in the column:

<th width='###px'>

or <td width='###px'>



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi

vacunita said:
<th width='###px'>

or <td width='###px'>
That should be either [tt]<td [maroon]width[/maroon][teal]=[/teal][green]"###"[/green]>[/tt] or [tt]<td [maroon]style[/maroon][teal]=[/teal][green]"width: ###px"[/green]>[/tt] : no unit in the [tt]width[/tt] attribute, unless it is [tt]%[/tt].

Alternatively you can put the [tt]width[/tt] in some [tt]col[/tt] tags too.

By the way, this has nothing to do with PHP.


Feherke.
 
Correct, on both counts. oops.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi and thanks. Yes I did actually try this and for reason it did not work. I also realise that it is not strictly php but I wondered if because the file is a php file this had anything to do why it wasn't working. So for example amongst others I tried: <td> width="###">".$row['EventName']."</td>
 
This is wrong, you can't close the <td> tag and then try to add an attribute.

Code:
<td[COLOR=white red]>[/color] width="###">

Look at our examples.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Man I wish there was an Edit post button.
Anyway, since your tags are already inside double quotes from the PHP string variable, you can't use double quotes.

So:
Code:
<td width=[COLOR=white red]'[/color]###[COLOR=white red]'[/color]>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thank you - stupid me. Didn't realise about the quote marks.
 
Hi

Now it indeed became PHP issue. The conclusion : if your code modification is not working, post that non-working code. Posting the original correct code does not help in debugging your mistake.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top