View Single Post
Old 10-04-2012, 09:02 PM   PM User | #1
Robbie8
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Robbie8 is an unknown quantity at this point
Question Re: Help on how to set column widths in php

Hi,
I am using a php view to show a table of all the entrants in my projects with their number, name, rounds and points.

I have two projects Project One and Two which have their results displayed in tables. The width of the columns for the values in these projects are dependent on the size of the name of the person, or club or points, making the table views slightly offset. The data records are read from a mysql database tables

i.e if the name is Fred Bloggs then the name column is only 11 characters wide, whereas if the name is Frederick Wilkinson then the column is 20 characters wide.
If Fred Bloggs is in project one and Frederick Wilkinson is in Project two, then when they are viewed on the web page then the Table for Project one is not as wide as for project two, making them look offset and not professional.

I would like to be able to define the width of each field, so as an example lets say the name field to be 25 characters and be padded with blanks if the name is shorter. Yes I understand that if the name was 26 characters it would be truncated and accept that, but as my individuals are fixed, I can live with that.

The php code is displayed below, but I don't know how to amend it to fix the column widths and would really appreciate some advice. I am sorry but I am not a php coder, so would appreciate instructions to update the code if at all possible?

--
PHP Code:
<?php
defined
('_JEXEC') or die('Restricted access'); ?>

<div id="Plans">

<h1><?php echo $this->title?></h1>

<table class="raceResults" cellspacing="0" cellpadding="0" summary="">
<thead>
<tr>
<th><?php echo JText::_('COM_Plans_POSITION_SHORT' ); ?></th>

<?php if ($this->params->get('shownumber')): ?>
<th><?php echo JText::_('COM_Plans_NUMBER_SHORT' ); ?></th>
<?php endif; ?>

<th><?php echo JText::_('COM_Plans_Individual' ); ?></th>

<?php if ($this->params->get('showteams')): ?>
<th><?php echo JText::_('COM_Plans_Team' ); ?></th>
<?php endif; ?>

<?php foreach ($this->rounds as $r): ?>
<th colspan="<?php echo count($r->subrounds); ?>" class="hasTip" title="<?php echo $r->round_name?>"><?php echo substr($r->short_name06); ?></th>
<?php endforeach; ?>

<th><?php echo JText::_('COM_Plans_Points' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$i 
0;
foreach( 
$this->rows AS $ranking )
{
$link_ind JRoute::_PlansHelperRoute::getIndividualRoute($ranking->slug$this->project->slug) );
$link_team JRoute::_PlansHelperRoute::getTeamRoute($ranking->teamslug$this->project->slug) );
?>
<tr class="<?php echo ($i 'd1' 'd0'); ?>">
<td><?php echo $ranking->rank?></td>

<?php if ($this->params->get('shownumber')): ?>
<td><?php echo $ranking->number?></td>
<?php endif; ?>

<td>
<a href="<?php echo $link_ind?>"
title="<?php echo JText::_('COM_Plans_Details' ); ?>">
<?php echo $ranking->first_name ' ' $ranking->last_name?>
</a>
</td>
<?php if ($this->params->get('showteams')): ?>
<td>
<?php if ($ranking->team_id): ?>
<a href="<?php echo $link_team?>"
title="<?php echo JText::_('COM_Plans_Details' ); ?>">
<?php echo $ranking->team_name?></a>
<?php endif; ?>
</td>
<?php endif; ?>

<?php $i 1;?>
<?php 
foreach ($this->rounds as $round): ?>
<?php 
foreach ($round->subrounds as $subround): ?>
<td><?php echo isset($ranking->results[$subround->subround_id]) ? $ranking->results[$subround->subround_id] : '-'?></td>
<?php endforeach; ?>
<?php 
endforeach; ?>

<td><?php echo $ranking->points?></td>

</tr>
<?php
$i 
$i;
}
?>
</tbody>
</table>
<p class="copyright">
<?php echo HTMLplans::footer( ); ?>
</p>
</div>

Last edited by Inigoesdr; 10-05-2012 at 12:31 AM..
Robbie8 is offline   Reply With Quote