datatable Incorrect column count

datatable Incorrect column count

SoldierBoYSoldierBoY Posts: 1Questions: 0Answers: 0

Greetings
I am facing an error when using datatable Incorrect column count my codes are as follows

<table class="table table-hover" id="datatableid">
    <thead>
        <tr>
            <th scope="col" data-title="id">#</th>
            <th scope="col" data-title="نام مشترک :">نام</th>
            <th scope="col" data-title="شماره موبایل مشترک :">موبایل</th>
            <th scope="col" data-title="خیابان و کوچه">خیابان و کوچه</th>
            <th scope="col" data-title="ساختمان">ساختمان</th>
            <th scope="col" data-title="پلاک یا واحد">پلاک یا واحد</th>
            <th scope="col" data-title="توضیحات">توضیحات</th>
            <th scope="col" data-title="وضغیت">وضعیت</th>
            <th scope="col" data-title="عملیات">عملیات</th>
        </tr>
    </thead>
    <tbody>
        <?php
        include_once('dbConnection.php');
        $database = new Connection();
        $db = $database->open();
        try {
            $sql = 'SELECT * FROM moshtariha ORDER BY id DESC';
            foreach ($db->query($sql) as $row) {
                ?>
                <tr>
                    <td scope="row"><?php echo $row['id']; ?></td>
                    <td><?php echo $row['name']; ?></td>
                    <td><?php echo $row['mobile']; ?></td>
                    <td><?php echo $row['address']; ?></td>
                    <td><?php echo $row['sakhteman']; ?></td>
                    <td><?php echo $row['pelak']; ?></td>
                    <td><?php echo $row['tozihat']; ?></td>
                    <td><?php
                        switch ($row['vaziyat']) {
                            case 1:
                                echo 'منزل نبود';
                                break;
                            case 2:
                                echo 'درحال برسی';
                                break;
                            case 3:
                                echo 'عدم تمایل';
                                break;
                            case 4:
                                echo 'ثبت نهایی';
                                break;
                        }
                        ?></td>
                    <td>
                        <a href="#edit_<?php echo $row['id']; ?>" class="btn btn-success btn-sm" data-bs-toggle="modal">ویرایش</a>
                        <a href="#delete_<?php echo $row['id']; ?>" class="btn btn-danger btn-sm" data-bs-toggle="modal">حذف</a>
                    </td>
                </tr>
                <tr>
                    <td >
                        <table class="table table-bordered datatable">
                            <thead>
                                <tr>
                                    <th>شماره</th>
                                    <th>متن کامنت</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                // Query to retrieve comments for current customer
                                $commentSql = 'SELECT * FROM comments WHERE customer_id = ' . $row['id'];
                                foreach ($db->query($commentSql) as $comment) {
                                    ?>
                                    <tr>
                                        <td><?php echo $comment['id']; ?></td>
                                        <td><?php echo $comment['text']; ?></td>
                                    </tr>
                                    <?php
                                }
                                ?>
                            </tbody>
                        </table>
                    </td>
                </tr>
                <?php include('edit-delete-modal.php'); ?>
                <?php
            }
        } catch (PDOException $e) {
            echo "خطای اتصال" . $e->getMessage();
        }
        //close connection
        $database->close();
        ?>
    </tbody>
</table>

where is the problem?

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Colin

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin

    The second row in your tbody lol only had a single column. So yes, I would expect it to give an error since DataTables requires all rows to have the same number if columns.

    Allan

Sign In or Register to comment.