Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

Dear Experts,

I am getting this error of incorrect column count in datatable, but I checked many times and columns count are not incorrect.

Please help.
Thanks in advance.

What I have tried:

PHP
<table id="example" class="table table-bordered table-striped table-sm">
                <?php if (isset($rows)) { ?>
                    <thead>
                        <tr>
                            <th colspan="16">Name: <?= $rows[0]['studentname']; ?> RollNo:  <?= $rows[0]['rollno']; ?></th>
                            <th colspan="16">Session: <?= getSessionById($sessionid); ?>  Class:  <?= getClassById($classid) ?>
                                 Section:  <?= getSectionByID($sectionid); ?>
                            </th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <th class="text-primary">Month</th>
                            <?php for ($i = 1; $i <= 31; $i++) { ?>
                                <th><?= $i; ?></th>
                            <?php } ?>
                            <td>Total</td>
                        </tr>
                        <?php foreach ($rows as $row) {
                            $l = 0;
                            $a = 0;
                            $t = 0;
                        ?>
                            <tr>
                                <td><?= $row['month']; ?></td>
                                <?php for ($i = 1; $i <= 31; $i++) {
                                    $field = 'day' . $i;  ?>
                                    <td><?= $row[$field] ?></td>
                                    <?php
                                    switch ($row[$field]) {
                                        case "L":
                                            $l += 1;
                                            break;
                                        case "A":
                                            $a += 1;
                                            break;
                                        case "T":
                                            $t += 1;
                                            break;
                                    }
                                    ?>
                                <?php } ?>
                                <td><?= "A=" . totalabsentiesM($row['enrollmentid'], 31, $row['month']) . ", L=" . totalleavesM($row['enrollmentid'], 31, $row['month']) . ""; ?></td>
                            </tr>
                        <?php  } ?>
                        <tr>
                            <td colspan="32"></td>
                            <td><?= "A=" . totalabsenties($row['enrollmentid'], 31) . ", L=" . totalleaves($row['enrollmentid'], 31) . ""; ?></td>
                        </tr>
                    </tbody>
                <?php  } ?>
            </table>
Posted
Updated 5-Jan-23 5:17am
v2
Comments
OriginalGriff 5-Jan-23 11:01am    
What have you checked?
How did you check it?
Where does it complain?

Just saying "it don't work" doesn't really help us to help you - we need actual information!

Use the "Improve question" widget to edit your question and provide better information.
nyt1972 5-Jan-23 11:07am    
I am using datatable, and it say:
DataTables warning: table id=example - Incorrect column count. For more information about this error, please see http://datatables.net/tn/18

Any way thanks, I found the problem,

DataTables does not support colspan or rowspan attributes on cells in the table body.

And I fixed it.

1 solution

Answered only to remove from unanswered list - solved by OP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900