Click here to Skip to main content
15,885,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My goal is that when I input a quantity of 5 and it's data for example is named "ABC-1000" the result is ABC-1000...ABC-1005, when I record another set of data and inputs any quantity it should start in ABC-1005, it's a little bit tricky for me, I am not sure if I should set another unique ID on it for me to get the last unique ID value and get the information inside my ajax call.

Here is my code in HTML
<div class="form-group">
       <label> Tools Name: </label>
       <select class="form-control selectpicker" name="tools_name"
        placeholder="Enter Tools Name" data-live-search="true"
        onchange="ToolsChange(this)">
        <option value="" selected disabled>Select Tools Name</option>
         <?php
           $query = "SELECT tools_masterlist.tools_id, 
                     tools_masterlist.control_no, 
                     tools_masterlist.tools_name, 
                     tools_spec.model_num,tools_spec.model_num_val 
                     FROM tools_spec 
                     LEFT JOIN tools_masterlist 
                     ON tools_spec.tools_id = tools_masterlist.tools_id 
                     WHERE status = 1 
                     ORDER BY tools_masterlist.tools_name";
           $con->next_result();
           // $result = mysqli_query($con, "CALL GetInformationUsingToolSpec()");
           $result=mysqli_query($con,$query);
            if(mysqli_num_rows($result)>0)
            {
               while($row=mysqli_fetch_assoc($result))
               {
                 echo '<option value="'.$row['tools_name'].'">' .  
                        $row['tools_name'].'</option>';
               }
            }                                               
         ?>
       </select>
</div>



Here is my AJAX
function ToolsChange(element) {
    let tools_id = $(element).val();

    if (tools_id) {

        $.ajax({
            type: "post",
            url: "form_JSON_approach.php",
            data: {
                "tools_id": tools_id
            },
            success: function(response) {

                var dataSplit = response;
                var shouldSplit = dataSplit.split(" ");
                console.log(shouldSplit[0]);
                console.log(shouldSplit[1]);
                $("#sel_control_num").val(shouldSplit[0]);
                $("#sel_tools_spec").val(shouldSplit[1]);

            }
        });
    }
}


Here is my query inside my ajax call.

<?php 

include("../include/connect.php");

 
    if(isset($_POST['tools_id'])){
        
        $ID = $_POST['tools_id'];
        
        $query = "SELECT tools_masterlist.control_no, tools_masterlist.tools_id, 
        tools_masterlist.tools_name, 
        tools_spec.model_num,tools_spec.model_num_val 
        FROM tools_spec 
        LEFT JOIN tools_masterlist 
        ON tools_spec.tools_id = tools_masterlist.tools_id 
        WHERE tools_name = '$ID'";
        $con->next_result();
        // $result=mysqli_query($con, "CALL GetAjaxForToolsRegistration('$ID')");
        $result=mysqli_query($con, $query);
        if(mysqli_num_rows($result)>0)
        {
            
            while($row = mysqli_fetch_assoc($result))
            {
                echo $row['control_no'] . " " . $row['model_num'];
            }
        
        }

    }


?>


What I have tried:

I have tried to do a query where in I joint the 3 queries in my database but logically error
Posted
Updated 21-Jan-21 14:17pm
v6

1 solution

If you are using HTML and javascript, you could store the last value in local storage. clearly you need to store it to check it later

Window localStorage Property[^]
 
Share this answer
 
Comments
pellanokeith07 21-Jan-21 19:35pm    
Hey thanks for answering! however I did not clearly get your explanation and I am using PHP and JQuery/Ajax
Christian Graus 21-Jan-21 19:37pm    
On the back end I think in PHP you can store a value in a session or globally. You are using Javascript in HTML, and that has a local storage store to put your values if you want them in the front end
pellanokeith07 21-Jan-21 19:51pm    
Ahhh okay I get it :) yeah if I want to see if I got the results that I want yes. But I have trouble figuring in the back-end side. Thank you very much for your 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