www.webdeveloper.com
Results 1 to 6 of 6

Thread: HTML table

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    HTML table

    hey guys,
    i have a PHP function that reads a file into a resulting array. i then need to use the rows in the PHP array to populate an HTML table. the problem is that the rows are a mixture of single elements (header lines) and rows of 5 elements (table columns). i need the single element rows to span across the 5columns where the tabbed data is below. all the data rows (with 5 elements) have a "+" sign in them, meaning that i can test for pos of + sign to determine whether the row is one header or 5 <TD>s. any pointers? i am thinking that JS is the way to go but i am new to that.

    thanks in advance,

    alan

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377


    For my clarification, could you supply the text (?) from the PHP or the resulting array (?)

    Just the heading and a few of the row lines as an example.

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    data

    ,
    FANTASY FOOTBALL LEAGUE ,
    TIES LOSE TIES LOSE TIES LOSE ,
    ,
    COL SAT OCT 8 2011 ,
    ,
    1. ARIZONA 2. OREGON ST + 1,
    3. GEORGIA 4. TENNESSEE U + 1,
    5. MIAMI OH 6. ARMY + 1,
    7. MISSOURI 8. KANSAS ST + 3,
    9. NAVY 10. SOU MISS + 3,
    11.ARIZ STATE 12. UTAH + 3,

    ^^^^that's what the data looks like
    all the rows that start with 1. 3. 5. 7.etc,... are the ones that need to
    go into 5 columns:

    1. // ARIZONA // 2. // OREGON ST // +1

    the other rows "TIES LOS...." etc need to center span across the whole table.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    What do you think about something like this
    Code:
    <script type="text/javascript">
    // the data without carriage return (*) (a simple preg_replace with PHP)  
    var data="FANTASY FOOTBALL LEAGUE ,TIES LOSE TIES LOSE TIES LOSE ,,COL SAT OCT 8 2011 ,,1. ARIZONA 2. OREGON ST + 1,3. GEORGIA 4. TENNESSEE U + 1,5. MIAMI OH 6. ARMY + 1,7. MISSOURI 8. KANSAS ST + 3,9. NAVY 10. SOU MISS + 3,11. ARIZ STATE 12. UTAH + 3";
    
    // Progressive replacements by using the regular expressions
    var datm=data.replace(/,(\d+\. )/g,'</td></tr>,<tr><td>$1</td><td>').replace(/ (\d+\. )/g,'</td><td>$1</td><td>').replace(/ (\+ \d+)/g,'</td><td>$1</td></tr>');
    var datn='<table><tr><td colspan="5">'+datm.replace(/,(?!<)/g,'</td></tr>,<td colspan="5">').replace(/,/g,'')+'</table>';
    
    // The result in form of HTML table  
    alert(datn)
    </script>
    We replace at first the comma followed by one or more digits, a point and a blank, then the single rank numbers, then the + signs. Then the commas not followed by a opening tag to finally remove the commas. Some classe (with the colspan="5") could achieve the look of the table

    (*) An other conditions like no comma at the beginning, blank before range number or plus sign, points after range number, never use of + sign (with two blanks) in names ... are necessary (particularly a blank after 11. and before ARIZONA STATE !).
    Last edited by 007Julien; 06-21-2012 at 09:52 AM. Reason: note and errors

  5. #5
    Join Date
    Jun 2012
    Posts
    3
    thanks a ton. i have not yet managed to master regex. i use grep all the time so i have a limited exposure to it. that being as it is, i think i can make your logic work - if not the actual syntax. i can take each row in the PHP result and wrap it in tags according to whether it needs to span or otherwise, and concat them into one string - voila = table. i'll let you know. thanks again,

    alan

    p.s i'll work on regex too.

  6. #6
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    On second thought, It is possible to go a little faster by deleting commas progressively during the processing...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles