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,$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, $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