CODEIGNITER: I want to automatic select the

In this my view diagram of sitting arangement.
VIEW:

                        <div class="card-body">
                            <label class="control-label">Seating Diagram</label>
                            <table id="seatsDiagram2">
                                <tr>
                                    <td id="seat-1" data-name="1">1</td>
                                </tr>
                            <tr>
                                    <td class="space">&nbsp; </td>
                            </tr>
                            
                                <tr>
                                    <td id="seat-2" data-name="2">2</td>
                                    <td id="seat-3" data-name="3">3</td>
                                    <td class="space">&nbsp; </td>
                                    <td class="space">&nbsp; </td>
                                    <td id="seat-4" data-name="4">4</td>
                                    <td id="seat-5" data-name="5">5</td>
                                    <td class="space">&nbsp; </td>
                                    <td id="seat-6" data-name="6">6</td>
                                    <td id="seat-7" data-name="7">7</td>
                                    <td class="space">&nbsp; </td>
                                    <td class="space">&nbsp; </td>
                                    <td id="seat-8" data-name="8">8</td>
                                    <td id="seat-9" data-name="9">9</td>
                                </tr>
                            <tr>
                                    <td class="space">&nbsp;</td>
                            </tr>
                                <tr>
                                <td id="seat-10" data-name="10">10</td>
                                </tr>
                            </table> 
                        </div>
                    </div> 

This is my script and I don’t know if my script is the reason why is not selecting automatic.

<script>
        document.addEventListener('DOMContentLoaded', function() {
            const sitNumbers = <?php echo json_encode(array_column($sit_numbers, 'pro_sitNumber'));?>;
            const cells = document.querySelectorAll('#seatsDiagram2 td');

            cells.forEach(cell => {
                const name = cell.getAttribute('data-name');
                if (sitNumbers.includes(name)) {
                    cell.classList.add('selected');
                }
            });
        });
</script>

This is CONTROLLER:

    $this->load->model('ProjectModel');
    $data['sit_numbers'] = $this->ProjectModel->get_sit_numbers();
    $this->load->view('project_view', $data);

This is MODEL:

    $sql = "SELECT * FROM `project`";
    $query=$this->db->query($sql);
    $result = $query->result();

Or maybe i have forgot something to put here to show the selected table.
This is the CSS:

#seatsDiagram2 td,
#displaySeats2 td{
    padding: 1rem;
    text-align: center;
    margin: 0.1rem;
    height: 57px;
    width: 60px;
    border: 3px solid transparent;
    display: inline-block;
    background-color: #efefef;
    border-radius: 4px;
    margin-inline-start: 4px;
    cursor: pointer;
}

#displaySeats2{
    margin: 3rem auto 1rem auto;
}

#seatsDiagram2{
    width: 100%;
    margin-bottom: 1rem;
    ;
    border: 1px solid gray;
}

#seatsDiagram2  td.selected{
    background-color: yellowgreen;
    -webkit-animation-name: rubberBand;
    animation-name: rubberBand;
    animation-duration: 300ms;
    animation-fill-mode: both;
}

#seatsDiagram2 td.notAvailable,
#displaySeats2 td.notAvailable
{
    color: white;
    background-color: #db2619;
}

#seatsDiagram2 td:not(.space,.notAvailable):hover{
    cursor: pointer;
    border-color:yellowgreen;
}

#seatsDiagram2 .space,
#displaySeats2 .space{
    background-color: white;
    border: none;
}

enter image description here
This is i want to see(check the image) and this reservation with table seating arrangement, and then sample is the client already reserve with table number and already save in database, if i view her reservation the table selected will show selected in the diagram.

Issues with Custom Walker_Nav_Menu for Columns in WordPress Navigation Menus

I’m trying to create a custom navigation menu in WordPress that uses invisible columns as containers for second-level menu items. I’m using a custom class that extends Walker_Nav_Menu, but I’m having trouble properly nesting the menu items within these columns.

Desired Menu Structure

Here’s how I want the structure of my menu to look:

<div class="children-wrapper">
    <div class="column-container">
        <li id="menu-item-98468" class="menu-column column-1 menu-item menu-item-type-custom menu-item-object-custom menu-item-98468">
            <a href="#">COLUMN-1</a>
            <ul class="sub-menu">
                <!-- Second-level items -->
            </ul>
        </li>
        <li id="menu-item-98460" class="menu-column column-2 menu-item menu-item-type-custom menu-item-object-custom menu-item-98460">
            <a href="#">COLUMN-2</a>
            <ul class="sub-menu">
                <!-- Second-level items -->
            </ul>
        </li>
    </div>
</div>

Current Menu Structure

<?php
class CustomWalker extends Walker_Nav_Menu {
    private $column_index = 0;
    private $in_column = false;

    function start_lvl(&$output, $depth = 0, $args = array()) {
        $indent = str_repeat("t", $depth);
        $n = "n";

        if ($depth === 0) {
            $output .= "{$n}{$indent}<div class="children-wrapper">{$n}";
            $output .= "{$indent}<div class="column-container">{$n}";
        } else {
            $classes = array('sub-menu');
            $class_names = join(' ', apply_filters('nav_menu_submenu_css_class', $classes, $args, $depth));
            $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
            $output .= "{$n}{$indent}<ul$class_names>{$n}";
        }
    }

    function end_lvl(&$output, $depth = 0, $args = array()) {
        $indent = str_repeat("t", $depth);
        $n = "n";

        if ($depth === 0) {
            $output .= "{$indent}</div><!-- .column-container -->{$n}";
            $output .= "{$indent}</div><!-- .children-wrapper -->{$n}";
        } else {
            $output .= "{$indent}</ul>{$n}";
        }
    }

    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        error_log("Depth: " . $depth . ", Item ID: " . $item->ID . ", Title: " . $item->title);
        $indent = ($depth) ? str_repeat("t", $depth) : '';
        $n = "n";

        $classes = empty($item->classes) ? array() : (array) $item->classes;

        // Check if this item is a column
        if (in_array('column-1', $classes) || in_array('column-2', $classes) || in_array('column-3', $classes)) {
            $this->in_column = true;
            $this->column_index++;
            $output .= "{$indent}<div class="menu-column column-{$this->column_index}">{$n}";
            $output .= "{$indent}<ul class="sub-menu">{$n}";
            return; // Don't output the column item itself
        }

        $this->output_item($output, $item, $depth, $args, $id);
    }

    function end_el(&$output, $item, $depth = 0, $args = array()) {
        $n = "n";

        $classes = empty($item->classes) ? array() : (array) $item->classes;

        if (in_array('column-1', $classes) || in_array('column-2', $classes) || in_array('column-3', $classes)) {
            $output .= "</ul>{$n}";
            $output .= "</div><!-- .menu-column -->{$n}";
            $this->in_column = false;
        } else {
            $output .= "</li>{$n}";
        }
    }

    private function output_item(&$output, $item, $depth, $args, $id) {
        $indent = ($depth) ? str_repeat("t", $depth) : '';
        $n = "n";

        $classes = empty($item->classes) ? array() : (array) $item->classes;
        $classes[] = 'menu-item-' . $item->ID;
        $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
        $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';

        $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
        $id = $id ? ' id="' . esc_attr($id) . '"' : '';

        $output .= $indent . '<li' . $id . $class_names .'>';

        $atts = array();
        $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
        $atts['target'] = !empty($item->target) ? $item->target : '';
        $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
        $atts['href'] = !empty($item->url) ? $item->url : '';

        $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);

        $attributes = '';
        foreach ($atts as $attr => $value) {
            if (!empty($value)) {
                $value = ('href' === $attr) ? esc_url($value) : esc_attr($value);
                $attributes .= ' ' . $attr . '="' . $value . '"';
            }
        }

        $title = apply_filters('the_title', $item->title, $item->ID);

        $item_output = $args->before;
        $item_output .= '<a'. $attributes .'>';
        $item_output .= $args->link_before . $title . $args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
    }
}
?>

Current Problem

The column items are being generated outside the column-container, and the second-level items are not being properly nested within these columns. I also think that the depthvariable isn’t working as it should be.
I’ll attach an image of what I’d like the menu structure to be

What I’ve Tried

I’ve tried modifying the start_el and end_el methods to properly nest the column items within the column-container, but the columns are still being generated outside of it. Any suggestions on how to fix this issue and properly nest the columns within the column-container?

Thank you in advance for your help!

I am struggling to get prefill data while editing document in php

<?php
session_start();
include '../config.php';

// Check if user is logged in
if (!isset($_SESSION['id'])) {
    echo ("<script LANGUAGE='JavaScript'>
            window.alert('Please Login First..!!!');
            window.location.href='index.php';
           </script>");
    exit();
}

$id = $_GET['id'];
$query = "SELECT * FROM tbl_associate_master WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
$associate = $result->fetch_assoc();
$stmt->close();

include 'intelmark_head.php';
include 'intelmark_sidebar.php';
?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Edit Associate</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">Edit Associate</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <form id="associateForm">
                <div class="card card-default">
                    <div class="card-header">
                        <h3 class="card-title">Edit Associate</h3>
                    </div>
                    <div class="card-body">
                        <input type="hidden" name="action" value="edit">
                        <input type="hidden" name="id" id="associate_id" value="<?php echo $associate['id']; ?>">
                        <div class="mine_box">
                            <div class="row">
                                <!-- Associate Name -->
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="associate_name">Associate Name</label>
                                        <input type="text" class="form-control" id="associate_name"
                                            name="associate_name" placeholder="Enter Associate Name"
                                            value="<?php echo $associate['associate_name']; ?>" required>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <!-- Contact Names in one line -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="contact_name1">Contact Name 1</label>
                                        <input type="text" class="form-control" id="contact_name1"
                                            name="contact_name1" placeholder="Enter Contact Name 1"
                                            value="<?php echo $associate['contact_name1']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="contact_name2">Contact Name 2</label>
                                        <input type="text" class="form-control" id="contact_name2"
                                            name="contact_name2" placeholder="Enter Contact Name 2"
                                            value="<?php echo $associate['contact_name2']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="contact_name3">Contact Name 3</label>
                                        <input type="text" class="form-control" id="contact_name3"
                                            name="contact_name3" placeholder="Enter Contact Name 3"
                                            value="<?php echo $associate['contact_name3']; ?>">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="addressContainer">
                            <div class="address_mine_box" style="margin-top: 20px;">
                                <div class="address-group">
                                    <div class="row">
                                        <!-- Address -->
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="address1_line1">Address</label>
                                                <input type="text" class="form-control" id="address1_line1"
                                                    name="address_line1[]" placeholder="Enter Address Line 1"
                                                    value="<?php echo $associate['address1_line1']; ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="address1_line2">Address Line 2</label>
                                                <input type="text" class="form-control" id="address1_line2"
                                                    name="address_line2[]" placeholder="Enter Address Line 2"
                                                    value="<?php echo $associate['address1_line2']; ?>">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <!-- Country, State, City -->
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="address1_country">Country</label>
                                                <select class="form-control" id="address1_country" name="country[]">
                                                    <option value="">Select Country</option>
                                                    <!-- Add PHP code to fetch and display countries -->
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="address1_state">State</label>
                                                <select class="form-control" id="address1_state" name="state[]">
                                                    <option value="">Select State</option>
                                                    <!-- Add PHP code to fetch and display states based on country -->
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="address1_city">City</label>
                                                <select class="form-control" id="address1_city" name="city[]">
                                                    <option value="">Select City</option>
                                                    <!-- Add PHP code to fetch and display cities based on state -->
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <!-- Pincode -->
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="address1_pincode">Pincode</label>
                                                <input type="text" class="form-control" id="address1_pincode"
                                                    name="pincode[]" placeholder="Enter Pincode"
                                                    value="<?php echo $associate['address1_pincode']; ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>&nbsp;</label><br>
                                                <button type="button" class="btn btn-secondary add-address-btn">Add Address</button>
                                                <button type="button" class="btn btn-danger remove-address-btn" style="display: none;">Remove Address</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Add more addresses as needed, similarly -->
                        </div>
                        <div class="mine_box">
                            <div class="row">
                                <!-- Phone -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="phone1">Phone</label>
                                        <input type="text" class="form-control" id="phone1" name="phone1"
                                            placeholder="Enter Phone" value="<?php echo $associate['phone_number1']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="phone2">Phone</label>
                                        <input type="text" class="form-control" id="phone2" name="phone2"
                                            placeholder="Enter Phone" value="<?php echo $associate['phone_number2']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="phone3">Phone</label>
                                        <input type="text" class="form-control" id="phone3" name="phone3"
                                            placeholder="Enter Phone" value="<?php echo $associate['phone_number3']; ?>">
                                    </div>
                                </div>

                                <!-- Email -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="email1">Email</label>
                                        <input type="email" class="form-control" id="email1" name="email1"
                                            placeholder="Enter Email" value="<?php echo $associate['email1']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="email2">Email</label>
                                        <input type="email" class="form-control" id="email2" name="email2"
                                            placeholder="Enter Email" value="<?php echo $associate['email2']; ?>">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="email3">Email</label>
                                        <input type="email" class="form-control" id="email3" name="email3"
                                            placeholder="Enter Email" value="<?php echo $associate['email3']; ?>">
                                    </div>
                                </div>
                                <!-- Website -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="website">Website</label>
                                        <input type="text" class="form-control" id="website" name="website"
                                            placeholder="Enter Website" value="<?php echo $associate['website']; ?>">
                                    </div>
                                </div>
                            </div>
                            <!-- Remark -->
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="remark">Remark</label>
                                    <textarea class="form-control" id="remark" name="remark"
                                        placeholder="Enter Remark"><?php echo $associate['remarks']; ?></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="card-footer">
                            <button type="submit" class="btn btn-primary">Update</button>
                        </div>
                    </div>
            </form>
        </div>
    </section>
</div>

<?php include 'intelmark_footer.php'; ?>
<style>
.mine_box {
    border: 1px solid #ddd;
    padding: 20px;
    margin: 20px 0;
    border-radius: 5px;
    background-color: #f9f9f9;
}
.address-group {
    margin-top: 20px;
    margin-bottom: 20px;
}
.address_mine_box {
    border: 1px solid #ddd;
    padding: 20px;
    margin: 20px 0;
    border-radius: 5px;
    background-color: #f9f9f9;
    margin-top: 20px;
}
.remove-address-btn {
    margin-top: 10px;
}
</style>

<script>
$(document).ready(function() {
    // Fetch countries and pre-select values
    $.ajax({
        url: 'city_state_country_fetch.php',
        type: 'GET',
        data: { type: 'countries' },
        success: function(response) {
            if (response.error) {
                console.error("Error fetching countries: " + response.error);
                return;
            }

            var countries = response;
            var options = "<option value=''>Select Country</option>";
            for (var i = 0; i < countries.length; i++) {
                options += "<option value='" + countries[i].id + "'>" + countries[i].country_name + "</option>";
            }
            $("[name='country[]']").html(options);

            // Pre-select country values
            var countryIds = [<?php echo $associate['address1_country_id']; ?>, <?php echo $associate['address2_country_id']; ?>, <?php echo $associate['address3_country_id']; ?>];
            $("[name='country[]']").each(function(index) {
                if (countryIds[index]) {
                    $(this).val(countryIds[index]).change();
                }
            });
        },
        error: function(xhr, status, error) {
            console.error("Error fetching countries: ", error);
        }
    });

    // Fetch states based on selected country and pre-select values
    $(document).on('change', '[name="country[]"]', function() {
        var countryId = $(this).val();
        var $stateSelect = $(this).closest('.address-group').find('[name="state[]"]');
        var $citySelect = $(this).closest('.address-group').find('[name="city[]"]');
        $citySelect.html("<option value=''>Select City</option>"); // Reset city dropdown

        $.ajax({
            url: 'city_state_country_fetch.php',
            type: 'GET',
            data: { type: 'states', country_id: countryId },
            success: function(response) {
                if (response.error) {
                    console.error("Error fetching states: " + response.error);
                    return;
                }

                var states = response;
                var options = "<option value=''>Select State</option>";
                for (var i = 0; i < states.length; i++) {
                    options += "<option value='" + states[i].id + "'>" + states[i].state_name + "</option>";
                }
                $stateSelect.html(options);

                // Pre-select state values
                var stateIds = [<?php echo $associate['address1_state_id']; ?>, <?php echo $associate['address2_state_id']; ?>, <?php echo $associate['address3_state_id']; ?>];
                var stateId = stateIds[$("[name='country[]']").index(this)];
                if (stateId) {
                    $stateSelect.val(stateId).change();
                }
            },
            error: function(xhr, status, error) {
                console.error("Error fetching states: ", error);
            }
        });
    });

    // Fetch cities based on selected state and pre-select values
    $(document).on('change', '[name="state[]"]', function() {
        var stateId = $(this).val();
        var $citySelect = $(this).closest('.address-group').find('[name="city[]"]');

        $.ajax({
            url: 'city_state_country_fetch.php',
            type: 'GET',
            data: { type: 'cities', state_id: stateId },
            success: function(response) {
                if (response.error) {
                    console.error("Error fetching cities: " + response.error);
                    return;
                }

                var cities = response;
                var options = "<option value=''>Select City</option>";
                for (var i = 0; i < cities.length; i++) {
                    options += "<option value='" + cities[i].id + "'>" + cities[i].city_name + "</option>";
                }
                $citySelect.html(options);

                // Pre-select city values
                var cityIds = [<?php echo $associate['address1_city_id']; ?>, <?php echo $associate['address2_city_id']; ?>, <?php echo $associate['address3_city_id']; ?>];
                var cityId = cityIds[$("[name='state[]']").index(this)];
                if (cityId) {
                    $citySelect.val(cityId);
                }
            },
            error: function(xhr, status, error) {
                console.error("Error fetching cities: ", error);
            }
        });
    });

    // Add more address fields
    $(document).on('click', '.add-address-btn', function() {
        if ($(".address-group").length < 3) {
            var addressGroup = $(".address_mine_box:first").clone();
            addressGroup.find("input").val("");
            addressGroup.find("select").val("");
            addressGroup.find(".add-address-btn").hide();
            addressGroup.find(".remove-address-btn").show();
            $("#addressContainer").append(addressGroup);
        } else {
            alert("You can only add up to 3 addresses.");
        }
    });

    // Remove address fields
    $(document).on('click', '.remove-address-btn', function() {
        $(this).closest('.address_mine_box').remove();
    });

    // Handle form submission
    $("#associateForm").submit(function(event) {
        event.preventDefault();
        var formData = $(this).serialize();

        $.ajax({
            url: 'intelmark_associate_master_action.php',
            type: 'POST',
            data: formData,
            success: function(response) {
                alert('Associate updated successfully');
                window.location.href = 'intelmark_associate_master.php';
            }
        });
    });
});

</script>

associate_edit.php
<?php
include '../config.php';

header('Content-Type: application/json');

$type = $_GET['type'];
$data = [];

try {
    if ($type == 'countries') {
        $query = "SELECT id, country_name AS name FROM tbl_countries_master";
    } elseif ($type == 'states' && isset($_GET['country_id'])) {
        $country_id = intval($_GET['country_id']);  // Ensure it's an integer
        $query = "SELECT id, state_name AS name FROM tbl_states_master WHERE country_id = $country_id";
    } elseif ($type == 'cities' && isset($_GET['state_id'])) {
        $state_id = intval($_GET['state_id']);  // Ensure it's an integer
        $query = "SELECT id, city_name AS name FROM tbl_cities_master WHERE state_id = $state_id";
    } else {
        throw new Exception('Invalid request');
    }

    $result = mysqli_query($conn, $query);

    if (!$result) {
        throw new Exception('Database query error: ' . mysqli_error($conn));
    }

    while ($row = mysqli_fetch_assoc($result)) {
        $data[] = $row;
    }

    echo json_encode($data);
} catch (Exception $e) {
    // Log the error message to a file or any other logging mechanism
    error_log($e->getMessage());

    // Send a JSON response with the error message
    echo json_encode(['error' => $e->getMessage()]);
}
?>

I have an associate database with country_id, state_id, and city_id fields. When I try to edit a record, all data is prefilled correctly, but the dropdown options for country, state, and city are not automatically selected based on the prefilled data. How can I ensure that these dropdowns show the selected values corresponding to the prefilled data when editing a record?

Extract first paragraph tag from the string [duplicate]

I have array of string with Headlines or without Headlines

$str = [
 "Hotel Rest Inn is a traveler's delight. It has 18 rooms in the heart of Bangalore"
"<p>HeadLine : Near Race Course Road</p><p>Location : With a stay at Le Meridien Bangalore</p>
];

I want extract Headline from the string if it exists. In the above example Near Race Course Road I want to extract and remove p tag having headline from the array

What I found by google Is

$string = preg_replace('~<p>(.*?)</p>~is', '$1', $string, /* limit */ 1);

this removes a string.

why I can not install laravel package? [closed]

appear a problem while Iam trying to install composer require tarfin-labs/laravel-spatial because Iam working on laravel 11 can any helps me to install it and can it cause a problem with laravel/multi-tenancy.

laravel programming php spatiaIndexs

How to send Data form while loop : while executing?

I am trying to send Tasks to all connected users (say 1000).
I am to select random task froma a list of 100 tasks and send to user 1 by 1 on an interval of 15sec. As soon as any user completes 5 tasks he sends notification to validate. The while loop pauses here to validate the tasks, and resumes upon validation. While loop stops when 5 users have submitted currect task. All this to be done within the loop of 100 task.

I have created this task.php. And installed Ratchet websocket. But i am unabe to figure out how to use ratchet function to send and receive data from task.php. I am working on this link example of websocket connection.

Is there any alternative way to do it. I am doing SSR theory now.

set_time_limit(0);              // making maximum execution time unlimited
ob_implicit_flush(1);           // Send content immediately to the browser on every statement which produces output
ob_end_flush();                 // deletes the topmost output buffer and outputs all of its contents


$frstSen = 'The First Task is : ';
$taskCalled = array();
$taskTotal = 0;

//Selecting random task from 1 to 100
in_array(($task = mt_rand(1,100)), array($taskCalled));

//Send the task : To the connected User
echo $frstSen.' '.$task.'<br/><br/>';
sleep(15);

//Pushing the previous called task to taskCalled list
array_push($taskCalled, $task);


    while($taskTotal = count($taskCalled) <= 99){
        
        //Selecting random task from 1 to 100 excluding the previous called task 
        in_array(($task = mt_rand(1,100)), array($taskCalled));
        
        //Send the task : To the connected User
        echo 'The Next Task is : '.$task.'<br/><br/>';

        //Pushing the previous called task to taskCalled list
        array_push($taskCalled, $task);
        
        sleep(15);
        
        $taskTotal = count($taskCalled);
        
    }

change woocommerce email field to phone number in order tracking form

To modify the code to use the billing_phone instead of the billing email for tracking the order in WooCommerce I have tried to write a part of code for using on my function.php child-theme, but this code not working and when user click on track order button nothing happen and redirected on home page.
Please check my code and give me some advices.

<?php
// override the default order tracking shortcode
function custom_order_tracking_shortcode() {
    remove_shortcode( 'woocommerce_order_tracking' );
    add_shortcode( 'woocommerce_order_tracking', 'custom_order_tracking_shortcode_output' );
}
add_action( 'init', 'custom_order_tracking_shortcode' );

// output the order tracking form and handle the tracking logic
function custom_order_tracking_shortcode_output( $atts ) {
    if ( is_null( WC()->cart ) ) {
        return;
    }

    $atts        = shortcode_atts( array(), $atts, 'woocommerce_order_tracking' );
    $nonce_value = wc_get_var( $_REQUEST['woocommerce-order-tracking-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) );

    if ( isset( $_REQUEST['orderid'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-order_tracking' ) ) {
        $order_id    = empty( $_REQUEST['orderid'] ) ? 0 : ltrim( wc_clean( wp_unslash( $_REQUEST['orderid'] ) ), '#' );
        $order_phone = empty( $_REQUEST['order_phone'] ) ? '' : wc_sanitize_phone_number( wp_unslash( $_REQUEST['order_phone'] ) );

        if ( ! $order_id ) {
            wc_print_notice( __( 'Please enter a valid order ID', 'woocommerce' ), 'error' );
        } elseif ( ! $order_phone ) {
            wc_print_notice( __( 'Please enter a valid phone number', 'woocommerce' ), 'error' );
        } else {
            $order = wc_get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );

            if ( $order && $order->get_id() && is_a( $order, 'WC_Order' ) && $order->get_billing_phone() === $order_phone ) {
                do_action( 'woocommerce_track_order', $order->get_id() );
                wc_get_template(
                    'order/tracking.php',
                    array(
                        'order' => $order,
                    )
                );
                return;
            } else {
                wc_print_notice( __( 'Sorry, the order could not be found. Please contact us if you are having difficulty finding your order details.', 'woocommerce' ), 'error' );
            }
        }
    }

    wc_get_template( 'order/form-tracking.php' );
}

// override the order tracking form template
function custom_order_tracking_form_template( $located, $template_name, $args, $template_path, $default_path ) {
    if ( 'order/form-tracking.php' === $template_name ) {
        $located = get_stylesheet_directory() . '/woocommerce/order/form-tracking.php';
    }
    return $located;
}
add_filter( 'wc_get_template', 'custom_order_tracking_form_template', 10, 5 );

// create the custom order tracking form template
function create_custom_order_tracking_form_template() {
    $form_tracking_template = <<<HTML
<form action="<?php echo esc_url( wc_get_page_permalink( 'track_order' ) ); ?>" method="post">
    <p><?php esc_html_e( 'To track your order, please enter your order number and mobile number in the boxes below and press the track button. The order number is provided to you through the receipt and SMS sent to you.', 'woocommerce' ); ?></p>
    <div style="display: flex; flex-wrap: wrap;">
        <p class="form-row form-row-first" style="flex: 1; padding-right: 10px;">
            <label for="orderid"><?php esc_html_e( 'Order ID', 'woocommerce' ); ?></label>
            <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php esc_attr_e( 'Found in your order confirmation email.', 'woocommerce' ); ?>" />
        </p>
        <p class="form-row form-row-last" style="flex: 1; padding-left: 10px;">
            <label for="order_phone"><?php esc_html_e( 'Billing Phone', 'woocommerce' ); ?></label>
            <input class="input-text" type="text" name="order_phone" id="order_phone" placeholder="<?php esc_attr_e( 'Billing phone number.', 'woocommerce' ); ?>" />
        </p>
    </div>
    <div class="clear"></div>
    <?php wp_nonce_field( 'woocommerce-order_tracking', 'woocommerce-order-tracking-nonce' ); ?>
    <p class="form-row">
        <button type="submit" class="button" name="track"><?php esc_html_e( 'Track', 'woocommerce' ); ?></button>
    </p>
</form>
HTML;

    $dir = get_stylesheet_directory() . '/woocommerce/order';
    if ( ! file_exists( $dir ) ) {
        mkdir( $dir, 0755, true );
    }

    file_put_contents( $dir . '/form-tracking.php', $form_tracking_template );
}
add_action( 'after_setup_theme', 'create_custom_order_tracking_form_template' );
?>

how can i change a variable after submition in symfony 7

i m trying to change a variable after i click on a submit button after verifying some conditions.
i used normal html forms instead of symfony forms idk if there is any difference.
controller:

#[Route('/test', name: 'test')]
    public function test(Request $request): Response
    {
        $response = 'a';
        if ($request->isMethod('POST')){
            $response = "value changed";
        }
        return $this->render('charge/test.html.twig', [
            'response' => $response
        ]);
    }

template:

{% extends 'base.html.twig' %}

{% block title %}Hello !{% endblock %}

{% block body %}
    <div class="container">
        <h1>{{ response }}</h1>
        <form method="post">
            <input type="submit" name="sub1" value="sub1">
            <input type="submit" name="sub2" value="sub2">
        </form>
    </div>
{% endblock %}

Value of response never changes after clicking on any of the submit buttons.

Probl;em in laravel install in larajon

Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
– spatie/laravel-ignition[2.0.0, …, 2.8.0] require ext-curl * -> it is missing from your system. Install or enable PHP’s curl extension.
– Root composer.json requires spatie/laravel-ignition ^2.0 -> satisfiable by spatie/laravel-ignition[2.0.0, …, 2.8.0].

To enable extensions, verify that they are enabled in your .ini files:
– D:laragonbinphpphp-8.3.8-Win32-vs16-x64php.ini
You can also run php --ini in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with --ignore-platform-req=ext-curl to temporarily ignore these required extensions.

please solve this problem

Laravel 10: Target class [AppHttpControllersappdashboarddashboardController] does not exist

I tried logging in a user (email and password) to the user’s dashboard page but got the error message:
Target class [AppHttpControllersappdashboarddashboardController] does not exist, after clicking the login button.

My expectations:
After a user has logged in and is authenticated the user is to be redirected to the dashboard page.
But instead I get this error:
Target class [AppHttpControllersappdashboarddashboardController] does not exist.
Look at the full description of what I’ve done:
I’ve written this code:

<x-layout.guest-layout>
        <form action="{{route('login.func')}}" method="post">

        @csrf

        <main class="flex flex-col justify-center items-center gap-3 py-4">

            <div>
                <h4>Login</h4>
            </div>

            @if (Session('success'))
                <p class="text-green-500 font-bold p-2 flex flex-row justify-center item-center">
                    {{Session('success')}}
                </p>
            @endif
            
            @if (Session('error'))
                <p class="text-red-500 font-bold p-2 flex flex-row justify-center item-center">
                    {{Session('error')}}
                </p>
            @endif
            
            @if (Session('exist'))
                <p class="text-gray40 font-bold p-2 flex flex-row justify-center item-center">
                    {{Session('exist')}}
                </p>
            @endif

            <div class="flex flex-col justify-start w-1/2">
                <label for="email">Email</label>
                <input class="rounded-md p-1 border focus:outline-green-500" type="email" name="email" id="email">

                {{-- error directives --}}
                @error('email')
                    <div class="font-semibold text-red-500 text-sm">
                        {{$message}}
                    </div>
                @enderror
                
            </div>
            
            <div class="flex flex-col justify-start w-1/2">
                <label for="password">Password</label>
                <input class="rounded-md p-1 border focus:outline-green-500" type="password" name="password" id="password">

                @error('password')
                    <div class="font-semibold text-red-500 text-sm">
                        {{$message}}
                    </div>
                @enderror
            </div>

            <div class="flex flex-col gap-2 w-1/2">
                <button class="text-white bg-green-500 font-bold rounded-md p-1">Login</button>
                <a href="/register" class="text-green-400 font-semibold">Create an Account</a>
            </div>
            
        </main>
    </form>
</x-layout.guest-layout>

within this file below:
Login page file location
that allows users to login, sending their credentials to be authenticated, into the file below:
Location of authentication controller file
which gets handled by the loginFunc method below:

<?php

namespace AppHttpControllersappauth;

use AppHttpControllersController;
use AppModelsUserModel;
use AppHttpControllersappdashboarddashController;
use IlluminateHttpRequest;
use IlluminateValidationValidationException;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesSession;

class authController extends Controller
{
    public function loginPage(){
        if (Session::get('userID')) {
            return redirect('/dashboard');
        }
        
        return view("app.pages.auth.loginPage");
 
    }

    public function registerPage(){
        if (Session::get('userID')) {
            return redirect('/dashboard');
        }
        return view("app.pages.auth.registerPage");
    }

    // public function dashboardPage(){
    //     if (!Session::get('userID')) {
    //         return Back()->with('', 'Access Denied');
    //     }
    //     return view('app.pages.dashboard.protectedDashPage');
    // }

    public function loginFunc(Request $request)
    {
        try {
            $request->validate([
                'email' => ['required', 'email'],
                'password' => ['required', 'string', 'min:8', 'max:15']
            ]);

            $existingUser = UserModel::where('email', $request->email)->first();

            if (!$existingUser /**$exitingUser->password !== $request->password*/) {
                return redirect('/')->with('exist', 'User does not exist');
            }elseif(!Hash::check($request->password, $existingUser->password)){
                return redirect('/')->with('error', 'Invalid email or password');
            }

            $request->session()->start();
            $request->session()->put('userID', $existingUser->id);
            return redirect('/dashboard');

        } catch (ValidationException $e) {
            return back()->withErrors($e->validator->errors());
        }//;
    }

using this route:

// Route to controller that processes form's input
Route::post('/login', [authController::class, 'loginFunc'])->name('login.func');

The loginFun authenticates the user, and if the user is authenticated, redirects the user to the dashboard page file:
location of dasboard bage file
Using the the last route in the code below:

<?php

use AppHttpControllersappauthauthController;
use AppHttpControllersappdashboarddashController;
use IlluminateSupportFacadesRoute;



// Route to pages
Route::get('/', [authController::class, 'loginPage'])->name('index.page');
Route::get('/register', [authController::class, 'registerPage'])->name('register.page');
Route::get('/about', [dashController::class, 'aboutPage'])->name('about.page');


Route::middleware('authM')->group(function () {
    Route::get('/dashboard',[dashController::class, 'dashboardPage'])->name('dashboard.page');
});

route to dashboard page file
This route points to two files. First the authM middleware file below:
Location of authM middleware file
Having the code below:

<?php

namespace AppHttpMiddleware;


use Closure;
use IlluminateHttpRequest;
use SymfonyComponentHttpFoundationResponse;
use IlluminateSupportFacadesSession;

class authM
{
    /**
     * Handle an incoming request.
     *
     * @param  Closure(IlluminateHttpRequest): (SymfonyComponentHttpFoundationResponse)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (!Session::get("userID")) {
            return redirect('/')->with('error', 'Please Login');
        }
        return $next($request);
    }
}

That prevents any unauthorise ascess to the dashboard page, and the dashController contoller file below:
Loction of the dashboard controller file
That contains the dashboardPage method below:

<?php

namespace AppHttpControllersappdashboard;

use AppHttpControllersController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesSession;

class dashController extends Controller
{
    public function aboutPage()
    {
        return view('app.pages.dashboard.about');
    }
    
    public function dashboardPage(){
        return view('app.pages.dashboard.protectedDashPage');
    }
}

Which renders the dashboard page (protectedDashPage.blade.php).
But I just keep getting the error:
Target class [AppHttpControllersappdashboarddashboardController] does not exist.
error message

operations required for a practical solution [closed]

I need a minimal solution like https://github.com/ankitpokhrel/tus-php that will send large files to the server.

  • index.html, js.js, upload.php
  • Consisting of only 3 files like,
  • Chunk size value can be adjusted,
  • Working with XMLHttpRequest,
  • without additional things like composer etc.
  • It can work sending 7GB files,
    Can you suggest a code example?

I wanted to request a complete solution that would perform all 3 operations required for a practical solution.

Reply Depend on current and previous Status

I have this code tend to achieve this

If the user has previously asked about Nrat and then says “Thank you”: The reply should respond with a specific Nrat-related response.
If the user just says “Thank you” without previously asking about Nrat: The reply should respond with a general “Thank you” response.

but reply always triggers to General thanks even user ask previous about Nrat

<?php
// include_once 'conection.php';

// session_start();

    if (isset($_SESSION['conversation_state'])) {
        $sessionUser = $_SESSION['conversation_state'];

        // Prepare and execute the query to fetch the conversation state
        $stmt = $mysqli->prepare("SELECT `last_intent`, `context` FROM `conversation_states` WHERE `Session_User` = ? ORDER BY `timestamp` DESC LIMIT 2");
        if ($stmt === false) {
            die('Prepare failed: ' . $mysqli->error);
        }
        
        $stmt->bind_param("s", $sessionUser);
        $stmt->execute();
        $result = $stmt->get_result();

        if ($result === false) {
            die('Execute failed: ' . $stmt->error);
        }

        if ($result->num_rows > 0) {
            $intents = [];
            while ($row = $result->fetch_assoc()) {
                $intents[] = $row['last_intent'];
            }
    

            $currentIntent = $intents[0];
        } 
            
    }else {
        
    }
    

    
    $checkcurrentStatus=false;

    
    function handleDialogyManagement( ) {
        global $lastIntent,$currentIntent,$checkcurrentStatus;
        $checkcurrentStatus=false;
        if($checkcurrentStatus){
            if($lastIntent === 'Murat_Identity' || $lastIntent === 'Murat_Office_Location'){
                $checkcurrentStatus=true;
                }else{
                    $checkcurrentStatus=false;
            }
         
        }
        
         // Check if last intent was 'Murat_Identity' or 'Murat_Office_Location' and current input is 'Thank_You'
         if (($lastIntent === 'Murat_Identity' || $lastIntent === 'Murat_Office_Location') && $currentIntent === 'Thank_You') {
           
         
            // Generate a random index to select one of the predefined responses
            $randomIndex = rand(0, 2); // Adjust the range based on the number of responses
    
            // Predefined responses based on your requirements
            $responses = [
                "I'm happy to help about Nrat. If you have another question, feel free to ask.",
                "I'm happy to further assist you about Nrat. You can like my response if it's helpful for my training.",
                "I'm grateful that my answer about Nrat has helped you. If you have another question, feel free to ask."
        
                // Add more responses here
            ];
    
            
            // Assign the selected response to the answer field in the response array
            $response['answer'] = $responses[$randomIndex];

            return $response;
        }

        // Check if last intent was 'Murat_Identity' or 'Murat_Office_Location' and current input is 'Thank_You'
        if ( $currentIntent === 'Thank_You' && $checkcurrentStatus===false) {
            // Generate a random index to select one of the predefined responses
            $randomIndex = rand(0, 2); // Adjust the range based on the number of responses
    
            // Predefined responses based on your requirements
            $responses = [
              "You're welcome! If you need further assistance, feel free to ask.",
"My pleasure. Let me know if there's anything else I can help with.",
"No problem! If you have any more questions, just let me know.",
"Anytime! I'm here whenever you need help.",
"Happy to help. Don't hesitate to reach out if you need anything else.",

            ];
    
            
            // Assign the selected response to the answer field in the response array
            $response['answer'] = $responses[$randomIndex];

            return $response;
        }

    
            
    
    }
    
    

?>

1-If the user has previously asked about Nrat and then says “Thank you”: The reply should respond with a specific Nrat-related response.

2-If the user just says “Thank you” without previously asking about Nrat: The reply should respond with a general “Thank you” response.

I got an error while sending notification [closed]

Can I ask? I coded the bot using JavaScript, but when I tested it, it said it was normal, but when I uploaded it to Git, it got an error, why?

Can I ask? I coded the bot using JavaScript, but when I tested it, it said it was normal, but when I uploaded it to Git, it got an error, why?.

Moxiemanager PHP8.2 “Trying to access array offset on value of type null” when uploading images

We’ve recently upgraded to PHP8.2 and are experiencing an issue uploading images with Moxiemanager, getting the error “Trying to access array offset on value of type null”. So it’s clearly stumbling over a null value in an array somewhere during the upload process but I’m having troubling identifying where, even with debug on. Can anyone help me pinpoint where in process it might be falling over?

(I’ve read this post: Issue with TinyMCE Moxiemanager on PHP8 and have applied the suggested changes, which resolved an earlier issue where the dialogue wouldn’t render).

Is Moxie supported in PHP8? The last changelog update is dated Feb 2020.