Jump to content

All Activity

This stream auto-updates

  1. Today
  2. Barand

    Report

    By the way @KAVIYA, I think you should get together with @Senthilkumar and join forces. His database name, column names and query contents and use of varchar for almost everything bear an amazing similarity to yours.
  3. Barand

    Report

    It helps if all the months that you searching for are the same. I can't see any data for 2024-04 in marketing_data table, so it gives this when I combine all
  4. KAVIYA

    Report

    Dear Mr.Barand, Thanks for your response for my post. I am writing the query to get the output of actual and target of three category from different tables. When I am writing query separately each category I am getting output. But when i am joining those queries, I am getting errors. For example, the below query to get the target and actual of machine details. SELECT Month,Name, ProductionTotal, ProductionActual FROM ( select count(a.id) as ProductionActual, Month, Fname from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND NOT (MCubicmeter = '0' AND MHourmeter ='0') AND Month='2024-01' group by Month, EmpID) ProductionActual LEFT JOIN (select count(a.id) as ProductionTotal, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID ) ProductionTotal USING (Month) I am getting the below output. Next when i am writing the below query to get the output if customer target and actual. SELECT Month,Name,CustomerTotal,CustomerActual FROM ( select count(a.id) as CustomerActual, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND (VisitType = 'No Due' OR VisitDate !='') AND Month='2024-04' group by Month, EmpID) CustomerActual LEFT JOIN (select count(a.id) as CustomerTotal, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-04' group by Month, EmpID ) CustomerTotal USING (Month, Name) I am getting the below output. When i am joining the above two query i am getting the category output only production output is not coming. Which ever is first, that output only coming. the join query is. SELECT Month,Name,CustomerTotal,CustomerActual, ProductionTotal, ProductionActual FROM ( select count(a.id) as CustomerActual, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND (VisitType = 'No Due' OR VisitDate !='') AND Month='2024-04' group by Month, EmpID) CustomerActual LEFT JOIN (select count(a.id) as CustomerTotal, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-04' group by Month, EmpID ) CustomerTotal USING (Month, Name) LEFT JOIN ( select count(a.id) as ProductionActual, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND NOT (MCubicmeter = '0' AND MHourmeter ='0') AND Month='2024-01' group by Month, EmpID) ProdAct USING (Month, Name) LEFT JOIN (select count(a.id) as ProductionTotal, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID ) ProductionTotal USING (Month, Name) and the join query output is single table is using to get the target and actual using above query But i am using two tables to get the target and actual for the third category marketing. Marketing query is SELECT Month,Fname,MarketingActual,MarketingTotal FROM ( select count(a.id) as MarketingActual, Month, Fname from sbms.marketing_data as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where b.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID) MarketingActual LEFT JOIN (select count(a.id) as MarketingTotal, Month, Fname as Name from sbms.marketing_target as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where b.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID) MarketingTotal USING (Month) and the output is But the marketing output should come like below image I need to combine all these three categories and the final output should come like below. Al my dumps are attached with the blow link for your reference. https://drive.google.com/file/d/1pRranTejVygkSaufLxjIbiiFdfyxlSDq/view?usp=sharing Please help me to solve this.
  5. I also discovered that i was using mariaDB which i have now changes to MYSQL as some of the JSON commends are different
  6. KAVIYA

    Report

    I'm getting results from the customer and production tables, but when I combine these two queries, I don't get any results from the tables.
  7. Yesterday
  8. gizmola

    My Intro

    Welcome to the forum. We are happy to have you here. If you have any questions let us know. I am glad to see you are taking things seriously and taking notes, while reading documentation. We really work best here, when people are asking questions about specific things they are working on, or having trouble with. The best way to learn initially is to build things.
  9. i tired .= but that didnt work so i went for foreach ($_POST['field'] as $k => $v) { $fieldSelection[$k] = ["fieldId" => $v, "fieldName" => $_POST['fieldName'][$k], "fieldLabel" => $_POST['fieldLabel'][$k], "fieldWidth" => $_POST['fieldWidth'][$k]]; } but i dont feel like this is the "right" way of doing it Thank you for finding the typo - been staring at this code for a long time now.
  10. except, that's only the last field definition, not all of them, because you are reassigning $fieldSelection each pass through the loop. you want to add a new array entry to $fieldSelection each pass through the loop. you have a typo/spelling mistake in the :fieldSection place-holder in the sql vs :fieldSelection in the execute() call.
  11. Barand

    Report

    You stand a better chance of help if you tell us exactly what your problem is we know what your data looks like (table structure and test data export dump) we know what output you want.
  12. OK, i think i have got to where i wanted to be - i dont know if i am being efficient at all. @Barand - i will take your advice on the order and increment once i have addressed my immediate problem. I now have the following function: function saveFormAndCustomFields($pdo) { file_put_contents("../post.log", print_r($_POST, true)); //if the form has not been submitted before if (!$_POST['formId']) { $sql2 = "INSERT INTO form (name, description, event_site_attachment_id, field_selection) VALUES (:name, :description, :esId, :fieldSelection)"; $stmt2 = $pdo->prepare($sql2); foreach ($_POST['field'] as $k => $v) { $fieldSelection = ["fieldId" => $v, "fieldName" => $_POST['fieldName'][$k], "fieldLabel" => $_POST['fieldLabel'][$k], "fieldWidth" => $_POST['fieldWidth'][$k]]; } $stmt2->execute([ ':name' => $_POST['formName'], ':description' => $_POST['formDescription'], ':esId' => $_GET['esId'], ':fieldSelection' => json_encode($fieldSelection) ]); $out = $pdo->LastInsertId(); return $out; } //if the form has been submitted before $sql2 = "UPDATE form SET name = :name, description = :description, field_selection = :fieldSection WHERE id = :formId"; $stmt2 = $pdo->prepare($sql2); foreach ($_POST['field'] as $k => $v) { $fieldSelection = ["fieldId" => $v, "fieldName" => $_POST['fieldName'][$k], "fieldLabel" => $_POST['fieldLabel'][$k], "fieldWidth" => $_POST['fieldWidth'][$k]]; } $stmt2->execute([ ':name' => $_POST['formName'], ':description' => $_POST['formDescription'], ':fieldSelection' => json_encode($fieldSelection), ':formId' => $_POST['formId'], ]); return $_POST['formId']; } the insert is working and the data looks like this { "fieldId": "4", "fieldName": "Custom 4", "fieldLabel": "Custom 4", "fieldWidth": "6" } The update, which in this instance i want to just completly replace the json contents is saying Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: The error code is $stmt2->execute([ ':name' => $_POST['formName'], ':description' => $_POST['formDescription'], ':fieldSelection' => json_encode($fieldSelection), ':formId' => $_POST['formId'], ]); i have var dumped post before the update showing me array(9) { ["formName"]=> string(3) "asa" ["formId"]=> string(3) "117" ["formDescription"]=> string(1) "a" ["field"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } ["fieldName"]=> array(2) { [0]=> string(11) "Custom 1111" [1]=> string(8) "Custom 2" } ["fieldLabel"]=> array(2) { [0]=> string(8) "Custom 1" [1]=> string(8) "Custom 2" } ["fieldType"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } ["fieldWidth"]=> array(2) { [0]=> string(1) "6" [1]=> string(1) "6" } ["ajax"]=> string(23) "saveFormAndCustomFields" } It looks to me like all of the values are available for this update so i am not sure what i am missing. I am not ignoring your advice above - i know it looks like i am. Apologioes forf that
  13. bugzorc

    My Intro

    Guess I fuck myself lol
  14. KAVIYA

    Report

    1.Production Target and Production Actual was attached the below SQL query. SELECT Month,Name, ProductionTotal, ProductionActual FROM ( select count(a.id) as ProductionActual, Month, Fname from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND NOT (MCubicmeter = '0' AND MHourmeter ='0') AND Month='2024-01' group by Month, EmpID) ProductionActual LEFT JOIN (select count(a.id) as ProductionTotal, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID ) ProductionTotal USING (Month) The output was executed for Production Target and Actual 2.Customer Target and Customer Actual was attached the below the SQL query. SELECT Month,Name,CustomerTotal,CustomerActual FROM ( select count(a.id) as CustomerActual, Month, Fname from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND (VisitType = 'No Due' OR VisitDate !='') AND Month='2024-04' group by Month, EmpID) CustomerActual LEFT JOIN (select count(a.id) as CustomerTotal, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-04' group by Month, EmpID ) CustomerTotal USING (Month) The output was executed for Customer Target and Actual 3.Marketing Target and Marketing Actual was attached the below the SQL query. It was not executed the query exact result. SELECT Month,Fname,MarketingActual FROM ( select count(a.id) as MarketingActual, Month, Fname from sbms.marketing_data as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where b.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID) MarketingActual LEFT JOIN (select count(a.id) as MarketingTotal, Month, Fname as Name from sbms.marketing_target as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where b.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID) MarketingTotal USING (Month) 4.If i joining two table Prodution and customer table output will be executed only for production query not in customer query. SELECT Month, Name, ProductionTotal, ProductionActual, CustomerTotal, CustomerActual FROM ( select count(a.id) as ProductionActual, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND NOT (MCubicmeter = '0' AND MHourmeter ='0') AND Month='2024-01' group by Month, EmpID) ProductionActual LEFT JOIN (select count(a.id) as ProductionTotal, Month, Fname as Name from sbms.production as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-01' group by Month, EmpID ) ProductionTotal USING (Month, Name) LEFT JOIN ( select count(a.id) as CustomerActual, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND (VisitType = 'No Due' OR VisitDate !='') AND Month='2024-04' group by Month, EmpID) CustomerActual USING (Month, Name) LEFT JOIN (select count(a.id) as CustomerTotal, Month, Fname as Name from sbms.customerdata as a inner join sbms.usertable as b on b.EmpNo = a.EmpID where a.Branch = '5' AND (b.Role='4' OR b.Role='5') AND Month='2024-04' group by Month, EmpID ) CustomerTotal USING (Month, Name) 5. Final output i want production ,customer,Marketing table within single query.
  15. Store the field sequence number as an attribute and don't rely on its position in the array. (This would apply equally to a conventional database table where you shouldn't rely on id for position). Also, have your sequence numbers initially incrementing by 10s (or, even, 100s). If you increment by 1, changing the sequence is a problem. EG if you start with firstname lastname date_of_birth username password and you then decide you want username to be first, you have to increment 1, 2, and 3 then change 4 to 1 (and run the risk of creating illegal duplicates on the way if you are using array positions or id keys). If you started with 100, 200, 300, .... then moving the username to the top would just be a matter of changing 400 to 50.
  16. Hi All, Sorry but i am really struggling with this...damn arrays. I dont think this option is going to work for me as the user has the ability to add as many fields as they want and move them around in order - the order is important so i would have to be constantly updating field names based on the order. The method which i am using now posts them in order negating this step. What is being posted is: array(9) { ["formName"]=> string(1) "q" ["formId"]=> string(0) "" ["formDescription"]=> string(1) "q" ["field"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } ["fieldName"]=> array(2) { [0]=> string(11) "Custom 1111" [1]=> string(8) "Custom 2" } ["fieldLabel"]=> array(2) { [0]=> string(8) "Custom 1" [1]=> string(8) "Custom 2" } ["fieldType"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } ["fieldWidth"]=> array(2) { [0]=> string(1) "6" [1]=> string(1) "6" } ["ajax"]=> string(23) "saveFormAndCustomFields" } I am trying to get the ids of the fields into the json column in my database ( to be clear i am able to do this but the keys are the issue). The data that is being posted - for example the below: ["field"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } using the following code if (!$_POST['formId']) { $sql2 = "INSERT INTO form (name, description, event_site_attachment_id, field_selection) VALUES (:name, :description, :esId, :fieldSelection)"; $stmt2 = $pdo->prepare($sql2); foreach ($_POST['field'] as $k => $v) { $fieldSelection[$k] = $v; } $stmt2->execute([ ':name' => $_POST['formName'], ':description' => $_POST['formDescription'], ':esId' => $_GET['esId'], ':fieldSelection' => json_encode($fieldSelection) ]); $out = $pdo->LastInsertId(); return $out; } is putting the following into the database ["1","2"] This is not unexpected based on the keys and values. What i would like to be in the database is something like the following { "formFields": [ { "id": 1, }, { "id": 2, }, { "id": 3, } ] } I am also posting other values that i will want to be in here at some point such as fieldWidth I think i am clearly misunderstanding the help that i have been given here so i apologise for that.
  17. bugzorc

    My Intro

    Here is some proof, to show am truly dedicated to learning php... If you noticed anything am doing wrong, tell me
  18. bugzorc

    My Intro

    Hi! Am Bugzorc, am into low level stuff, but kinda in love with php since the day I got into tech, been learning it for like a 2 weeks now(still only printing hello world and playing with strings eg reverse, explode), I see the forums is pretty good, especially IDK barrand hope I got ur name right, any I think am gonna be here for a long time, possibly till death, anyways users like idk barrand the other eg: admin with a cute child pfp, do you mind giving an advice or tips as I dwell in ma journey of learning php or anything, would truly appreciate it, thank you... But I haven't finished the basics yet, still learning on W3schools, then imma start a project may be to get out of tutorial hell... again, how do I change my pfp?
  19. Last week
  20. I find data attributes useful for associating inputs for the same record. I get the data-id of the select field then change other fields with the same data-id. Here's an example <php $employees = [ [ 'id'=>21, 'name'=>'Curly', 'status'=>1, 'title'=>'Sales Manager', 'salary'=>65000 ], [ 'id'=>22, 'name'=>'Larry', 'status'=>1, 'title'=>'Sales Assistant', 'salary'=>45000 ], [ 'id'=>33, 'name'=>'Mo', 'status'=>1, 'title'=>'Sales Assistant', 'salary'=>45000 ], [ 'id'=>46, 'name'=>'Tom', 'status'=>1, 'title'=>'Sales Assistant', 'salary'=>45000 ], [ 'id'=>47, 'name'=>'Dick', 'status'=>1, 'title'=>'Trainee', 'salary'=>25000 ], [ 'id'=>51, 'name'=>'Harry', 'status'=>1, 'title'=>'Trainee', 'salary'=>25000 ] ]; $tdata = ''; foreach ($employees as $e) { $tdata .= "<tr> <td>{$e['name']}</td> <td><select name='emp[{$e['id']}][status]' class='status' data-id='{$e['id']}'>" . statusOptions($e['status']) . "</td> <td><input type='text' name='emp[{$e['id']}][title]' class='title' data-id='{$e['id']}' value='{$e['title']}'></td> <td><input type='text' name='emp[{$e['id']}][salary]' class='salary' data-id='{$e['id']}' value='{$e['salary']}'></td> </tr>"; } function statusOptions($current) { $stats = [1 => "Working", 2 => "Not Working"]; $opts = "<option value=''>- select status -</option>"; foreach ($stats as $s => $desc) { $sel = $s == $current ? 'selected' : ''; $opts .= "<option $sel value='$s'>$desc</option>"; } return $opts; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example</title> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <script type='text/javascript'> $(function() { $(".status").change(function() { let id = $(this).data("id") if ( $(this).val() == 2 ) { $(".title[data-id="+id+"]").attr("disabled", true) $(".salary[data-id="+id+"]").attr("disabled", true) } else { $(".title[data-id="+id+"]").attr("disabled", false) $(".salary[data-id="+id+"]").attr("disabled", false) } }) }) </script> <style type='text/css'> table { border-collapse: collapse; width: 80%; margin: 30px auto; } th { text-align: left; padding: 8px; color: white; background-color: black; } td { padding: 4px 8px; } </style> </head> <body> <h1>Example</h1> <form method='POST'> <table border='1'> <tr> <th>Name</th> <th>Status</th> <th>Job Title</th> <th>Salary</th> </tr> <?= $tdata ?> <tr><td colspan='4'><input type='submit'></tr> </table> </form> </body> </html>
  21. I didn't create a Model, but a trait though maybe it will give you some ideas? <?php // NavigationMenuTrait.php namespace clearwebconcepts; use function htmlspecialchars; use function hash_equals; trait NavigationMenuTrait { public function regular_navigation(): void { $navItems = [ 'Home' => 'index.php', 'About' => 'about.php', 'Puzzle' => 'puzzle.php', 'Portfolio' => 'portfolio.php', 'Contact' => 'contact.php' ]; // Check if the user is logged in $isLoggedIn = isset($_COOKIE['login_token']) && isset($_SESSION['login_token']) && hash_equals($_SESSION['login_token'], $_COOKIE['login_token']); if ($isLoggedIn) { unset($navItems['Home']); // Remove 'Home' from the navigation menu // Add 'Dashboard' to the start of the navigation menu $navItems = array('Dashboard' => 'dashboard.php') + $navItems; } else { $navItems['Login'] = 'login.php'; // Add 'Login' to the navigation menu } $navLinks = []; foreach ($navItems as $title => $path) { $href = $this->generateHref($path); $safeTitle = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); $navLinks[] = "<a href=\"{$href}\">{$safeTitle}</a>"; } // Check if the user is logged in if ($isLoggedIn) { $navLinks[] = '<a href="logout.php">Logout</a>'; // Add 'Logout' to the end of the navigation menu } echo implode('', $navLinks); } public function showAdminNavigation(): void { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https://' : 'http://'; $host = $_SERVER['HTTP_HOST']; // Define your base path here $base_path = ($host === 'localhost:8888') ? '/clearwebconcepts' : ''; $base_url = $protocol . $host . $base_path; $adminItems = [ 'Create Entry' => $base_url . '/create_cms.php', 'Edit Entry' => $base_url . '/edit_cms.php', 'Add to Portfolio' => $base_url . '/new_portfolio.php', 'Edit Portfolio Page' => $base_url . '/edit_portfolio.php', 'Add Jigsaw' => $base_url . '/add_to_puzzle.php', 'Edit Jigsaw' => $base_url . '/edit_puzzle.php', 'Service Form' => $base_url . '/service_form.php' ]; echo '<div class="admin-navigation">'; foreach ($adminItems as $adminTitle => $adminPath) { $adminSafeTitle = htmlspecialchars($adminTitle, ENT_QUOTES, 'UTF-8'); echo "<a href=\"{$adminPath}\">{$adminSafeTitle}</a>"; } echo '</div>'; } private function generateHref(string $path): string { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https://' : 'http://'; $host = $_SERVER['HTTP_HOST']; // Define your base path here $base_path = ($host === 'localhost:8888') ? '/clearwebconcepts' : ''; $base_url = $protocol . $host . $base_path; // Build the URL first, then validate it $url = $base_url . '/' . $path; $sanitized_url = filter_var($url, FILTER_SANITIZE_URL); $valid_url = filter_var($sanitized_url, FILTER_VALIDATE_URL); if ($valid_url === false) { die('Invalid URL'); } return $valid_url; } }
  22. Dear Team, I have a table which is generating data dynamically. Below is my table My table code is <table id="product_data" class="table table-striped table-bordered nowrap table-sm" style="width:100%;"> <thead class="bg-blue text-center"> <tr> <th style="width: 5%; vertical-align: middle">S.No</th> <th style="width: 25%; vertical-align: middle">Customer Name</th> <th style="width: 12%; vertical-align: middle">Location</th> <th style="width: 8%; vertical-align: middle">Model</th> <th style="width: 8%; vertical-align: middle">Machine S.No</th> <th style="width: 10%; vertical-align: middle">Machine Status</th> <th style="width: 8%; vertical-align: middle">Monthly (Cu.m) <span class="text-danger">*</span></th> <th style="width: 8%; vertical-align: middle">Total (Cu.m)</th> <th style="width: 8%; vertical-align: middle">Monthly (Hr.m)</th> <th style="width: 8%; vertical-align: middle">Total (Hr.m)</th> </tr> </thead> <tbody> <?php $n = 1; $sql = "select * from machinemaster AS a INNER JOIN machineassign AS b ON b.RowID = a.id WHERE b.EmpID = '$EmpNo'"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_assoc($result)) { $ID = $row['id']; $CustomerName = $row['CustomerName']; $MachineLocation = $row['MachineLocation']; $Model = $row['Model']; $MachineNo = $row['MachineSlNo']; $RowID = $row['RowID']; ?> <tr> <td align='center'> <?php echo $n++; ?> </td> <td> <?php echo $CustomerName; ?> </td> <td> <?php echo $MachineLocation; ?> </td> <td> <?php echo $Model; ?> </td> <td> <?php echo $MachineNo; ?> </td> <td> <select name='Ststus[]' id='Status<?php echo $RowID; ?>' class='form-control Status' style="width:auto"> <option value='1'>Working</option> <option value='0'>Not Working</option> </select> </td> <td align='center' hidden> <input type="number" name="RowID[]" id="RowID<?php echo $RowID; ?>" value="<?php echo $RowID; ?>" class="form-control" autocomplete="off" /> </td> <td align='center'> <input type="number" name="MCubicmeter[]" id="MCubicmeter<?php echo $RowID; ?>" value="" class="form-control MCubicmeter text-center cucalc" autocomplete="off" /> </td> <td align='center'> <input type="number" name="TCubicmeter[]" id="TCubicmeter<?php echo $RowID; ?>" value="" class="form-control TCubicmeter text-center " autocomplete="off" readonly /> </td> <td align='center'> <input type="number" name="MHourmeter[]" id="MHourmeter<?php echo $RowID; ?>" value="" class="form-control MHourmeter text-center" autocomplete="off" /> </td> <td align='center'> <input type="number" name="THourmeter[]" id="THourmeter<?php echo $RowID; ?>" value="" class="form-control THourmeter text-center" autocomplete="off" readonly /> </td> <td hidden> <input type="number" name="lang[]" value="<?php echo $RowID; ?>" class="form-control" autocomplete="off" /> </td> </tr> <?php } ?> </tbody> </table> In this table, the machine status is a dropdown (Working & Networking). When I select the not working on any row, the Monthly (Cu.m) & Monthly (Hr.m) columns should disabled. otherwise, it should be editable. I have tried the below code. <script> $(document).on('change', '#product_data tbody tr td:nth-child(6)', function () { var rowvlaue = row($(this).closest('tr')).data()[12]; }); </script> Afte this I am not sure how to go ahead. Please help me how to complete this.
  23. if you name the sets of fields differently, with the same root name, an incrementing numerical index, then the element name, the submitted data will already be in a format that you can json_encode(). assuming these are all text fields, the markup would look like - <input type='text' name='fieldSelection[0][field]'> <input type='text' name='fieldSelection[0][fieldName]'> <input type='text' name='fieldSelection[0][fieldLabel]'> <input type='text' name='fieldSelection[0][fieldType]'> <input type='text' name='fieldSelection[0][fieldWidth]'> <input type='text' name='fieldSelection[1][field]'> <input type='text' name='fieldSelection[1][fieldName]'> <input type='text' name='fieldSelection[1][fieldLabel]'> <input type='text' name='fieldSelection[1][fieldType]'> <input type='text' name='fieldSelection[1][fieldWidth]'> you can then simply loop over $_POST['fieldSelection'] and use each set of values - foreach($_POST['fieldSelection'] as $row) { echo '<pre>'; print_r($row); echo '</pre>'; echo json_encode($row); echo '<br>'; }
  24. The keys were 0, 1. This what you have in your table. Examples... $sql2 = "INSERT INTO test_1 (field_selection) VALUES (:fids)"; $stmt2 = $pdo->prepare($sql2); $fieldIds = [0=>1, 1=>2]; $stmt2->execute([ ':fids' => json_encode($fieldIds) ]); $fieldIds = [42=>1, 57=>2]; $stmt2->execute([ ':fids' => json_encode($fieldIds) ]); // GIVES: // +----+---------------------+--------------------+ // | id | created | field_selection | // +----+---------------------+--------------------+ // | 1 | 2024-03-01 00:09:04 | [1, 2] | // | 2 | 2024-03-01 00:09:04 | {"42": 1, "57": 2} | // +----+---------------------+--------------------+
  25. This is what is posted. array(9) { ["formName"] => string(3) "asa" ["formId"] => string(0) "" ["formDescription"] => string(5) "asasa" ["field"] => array(2) { [0] => string(1) "1" [1] => string(1) "2" } ["fieldName"] => array(2) { [0] => string(11) "Custom 1111" [1] => string(8) "Custom 2" } ["fieldLabel"] => array(2) { [0] => string(8) "Custom 1" [1] => string(8) "Custom 2" } ["fieldType"] => array(2) { [0] => string(1) "1" [1] => string(1) "2" } ["fieldWidth"] => array(2) { [0] => string(1) "6" [1] => string(1) "6" } ["ajax"] => string(23) "saveFormAndCustomFields" }
  26. What do you expect to be getting? What's in $_POST['field'] ?
  27. OK, so i have got data going in which is great. I am trying to get the key in the array as well as the value (it should be fieldId) - currently when submitting 2 objects with id 1 and 2 i am getting ["1","2"] The function is below if (!$_POST['formId']) { $sql2 = "INSERT INTO form (name, description, event_site_attachment_id, field_selection) VALUES (:name, :description, :esId, :fieldSelection)"; $stmt2 = $pdo->prepare($sql2); foreach ($_POST['field'] as $k => $v) { $fieldSelection[$k] = $v; } $stmt2->execute([ ':name' => $_POST['formName'], ':description' => $_POST['formDescription'], ':esId' => $_GET['esId'], ':fieldSelection' => json_encode($fieldSelection) ]); $out = $pdo->LastInsertId(); return $out; }
  28. Great response! I've definitely thought of just creating my own way & then improving on it later. Also, here's what the multilevel menu recursive function would look similar to: <?php $conn = new PDO('mysql:host=localhost; dbname=Mydb', 'MyUsername', 'MyPassword'); function left_nav($parent_id, $conn){ $sql = 'SELECT * FROM navs WHERE parent_id = ?'; $stmt = $conn->prepare($sql); $stmt->bindParam(1, $parent_id, PDO::PARAM_INT); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); if($data){ echo "<ul>\n"; foreach ($data as $row) { echo "<li><a href='#'>{$row['nav_item_name']}</a>"; # Recursive (function calls itself in loop) call for sub-items left_nav($row['id'], $conn); echo "</li>\n"; } echo "</ul>"; } } # Start 'left_nav()' function to build navigation from root level (parent_id = 0) left_nav(0, $conn);
  1. Load more activity
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.