Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,627
    Thanks
    0
    Thanked 646 Times in 636 Posts
    It would be far easier to just set a column min-width in the CCS. You can set column specific information for the table by assigning classes inside the <col> and <colgroup> tags that precede the <thead> tag.

    The other thing you haven't taken into account is that with most fonts the characters are not all the same width and so iiiiiiiiiiiiiiiiiiiiiiiii is not the same width as MMMMMMMMMMMMMMMMMMMMMMMMM even though both are 25 characters long.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    I have sussed the problem by coding the following into my code - this is giving me what I need and I have tested all of the possibilities and it works as I need it to.

    <td width="5px"> etc

    to each field


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •