0

I am using this code to generate a table which will subsequently be modified to upload data to a mysql database.

<?php
$start_loc_number= 1 ;
$start_loc_alpha= 'A' ;
$end_loc_number= 10 ;
$end_loc_alpha= 'J' ;

$out = ''; 

   $out .= '<table border = 1 bordercolor="#FF0000">';

    for($tr='A';$tr<=$end_loc_alpha;$tr++)
    { $out .= "<tr>";
        for($td=1;$td<=$end_loc_number;$td++)
        { $out .= '<td BGCOLOR="#99CCFF">'.$tr.$td.'</td>

                                 <td id="sampleID" contenteditable="true">  sampleID</td>
                                 <td id="volume" contenteditable="true">  volume</td>'  ;
        }
    $out .= "</tr>";
    }

    $out .= "</table>";

echo $out; 
?>

At the moment the table generates 3 cells per iteration in 3 column cells,

| coordinates | sample ID | volume |

My question relates to how the php code can be altered so to generate a table where the coordinates cell can be arranged as a rowspan over the sampleID and volume cells positioned in 2 rows with the sample ID over the volume cell

|             | sample ID
| coordinates |------------
|             | volume
2
  • why don't you make a table with two row inside your td ? Commented Mar 30, 2015 at 11:21
  • that's what I've tried but have had no success Commented Mar 30, 2015 at 11:22

3 Answers 3

1

try this,

for($tr='A';$tr<=$end_loc_alpha;$tr++)
    { $out .= "<tr>";
        for($td=1;$td<=$end_loc_number;$td++)
        { $out .= '<td BGCOLOR="#99CCFF">'.$tr.$td.'</td><td>
                                <table><tr style="border-bottom: 1px solid red">
                                 <td id="sampleID" contenteditable="true">  sampleID</td></tr>
                                <tr> <td id="volume" contenteditable="true">  volume</td></tr></table></td>'  ;
        }
    $out .= "</tr>";
    }
Sign up to request clarification or add additional context in comments.

Comments

1

This works for me

<table>
    <tr>
        <td rowspan="2">test</td>
        <td>test1</td>
    </tr>
    <tr>
        <td>test2</td>
    </tr>
</table>

EDIT : fiddle

1 Comment

thanks but I was inquiring about the code rather than the HTML per se +1 in any case
1

you can set rowspan="2" on your coords TD.

You really should not build your output like that. Try this approach:

<?php

$content = array(
    array(
        'cords' => 1,
        'samp' => "Bar",
        'vol' => 13
    ),
    array(
        'cords' => 2,
        'samp' => "Foo",
        'vol' => 456
    ),
    array(
        'cords' => 3,
        'samp' => "DJ",
        'vol' => 34
    )
);

?>

<table>
    <tbody>
        <? foreach($content as $key => $value) { ?>
        <tr>
            <th rowspan="2">Coordinates: <?= $value['cords'] ?></th>
            <td>sample ID: <?= $value['samp'] ?></td>
        </tr>
        <tr>
            <td>volume: <?= $value['vol'] ?></td>
        </tr>
        <? } ?>
    </tbody>
</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.