Senthilkumar Posted July 19, 2023 Share Posted July 19, 2023 Dear Team, I am having a table which is displaying actual and target values from two different mysql table. My table is In above table when i am selecting the month the actual and target date should display from the databse. When i am using the bellow code all the target value is displaying <script>//..................month hide function function myFunction() { var month = document.getElementById("month").value; var dealerid = document.getElementById("dealerid").value; $.ajax({ type: 'POST', dataType: 'JSON', url: 'Revenue_Data.php', data: 'month=' + month + '&dealerid=' + dealerid, //data: 'month=' + month + '&dealerid=' + dealerid, success: function (response) { //var jsonData = JSON.parse(response); var len = response.length; //alert(jsonData); for (var i = 0; i < len; i++) { var Category_Name = response[i].Category_Name; var Description = response[i].Description; var Month_Value = response[i].Month_Value; var result = response[i].result; //var Excavator = response[i].Excavator; //var Grader = response[i].Grader; //var WheelLoader = response[i].WheelLoader; //var SLM = response[i].SLM; //var Parts_Service_ID = response[i].Parts_Service_ID; //var Revanue = response[i].Revanue; //var Margin = response[i].Margin; document.getElementById(result).value = Month_Value; //document.getElementById('ExcavatorActual'+Parts_Service_ID).value = Excavator; //document.getElementById('GraderActual'+Parts_Service_ID).value = Grader; //document.getElementById('WheelLoaderActual'+Parts_Service_ID).value = WheelLoader; //document.getElementById('SLMActual'+Parts_Service_ID).value = SLM; //document.getElementById('RevenueActual'+Parts_Service_ID).value = Revanue; //document.getElementById('Margin'+Parts_Service_ID).value = Margin; } } }); } </script> <?php // Include the database config file include("../connection.php"); //error_reporting(0); error_reporting(E_ALL); ini_set('display_errors', '1'); //ini_set('display_errors','Off'); if(!empty($_POST["month"]) ){ $Month=$_POST["month"]; $dealerid = $_POST["dealerid"]; $Mon = date('M', strtotime($Month)); $sql = "select $Mon,Category_Name,Description from revenuetarget WHERE Dealer_ID = '$dealerid'"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_array($result)) { $Category_Name = $row['Category_Name']; $Description = $row['Description']; $Month_Value = $row[$Mon]; $Description1= str_replace(' ', '', $Description); $Category_Name1= str_replace(' ', '', $Category_Name); $result1 = trim($Category_Name1); $result1 .= trim($Description1); $return_arr[] = array( "Category_Name" => $Category_Name, "Description" => $Description, "result" => $result1, "Month_Value" => $Month_Value, ); } $sql = "select * from revenue_data WHERE dealerid = '$dealerid' AND month = '$Month'"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_array($result)) { $Excavator = $row['Excavator']; $Grader= $row['Grader']; $WheelLoader = $row['WheelLoader']; $SLM = $row['SLM']; $Parts_Service_ID = $row['Parts_Service_ID']; $Revanue = $row['Revanue']; $Margin = $row['Margin']; $return_arr1[] = array( "Excavator" => $Excavator, "Grader" => $Grader, "WheelLoader" => $WheelLoader, "SLM" => $SLM, "Parts_Service_ID" => $Parts_Service_ID, "Revanue" => $Revanue, "Margin" => $Margin, ); } echo json_encode($return_arr); //echo json_encode($return_arr1); } ?> When i am using the bellow code all my actual values are displaying <script>//..................month hide function function myFunction() { var month = document.getElementById("month").value; var dealerid = document.getElementById("dealerid").value; $.ajax({ type: 'POST', dataType: 'JSON', url: 'Revenue_Data.php', data: 'month=' + month + '&dealerid=' + dealerid, //data: 'month=' + month + '&dealerid=' + dealerid, success: function (response) { //var jsonData = JSON.parse(response); var len = response.length; //alert(jsonData); for (var i = 0; i < len; i++) { //var Category_Name = response[i].Category_Name; //var Description = response[i].Description; //var Month_Value = response[i].Month_Value; //var result = response[i].result; var Excavator = response[i].Excavator; var Grader = response[i].Grader; var WheelLoader = response[i].WheelLoader; var SLM = response[i].SLM; var Parts_Service_ID = response[i].Parts_Service_ID; var Revanue = response[i].Revanue; var Margin = response[i].Margin; //document.getElementById(result).value = Month_Value; document.getElementById('ExcavatorActual'+Parts_Service_ID).value = Excavator; document.getElementById('GraderActual'+Parts_Service_ID).value = Grader; document.getElementById('WheelLoaderActual'+Parts_Service_ID).value = WheelLoader; document.getElementById('SLMActual'+Parts_Service_ID).value = SLM; document.getElementById('RevenueActual'+Parts_Service_ID).value = Revanue; document.getElementById('Margin'+Parts_Service_ID).value = Margin; } } }); } </script> <?php // Include the database config file include("../connection.php"); //error_reporting(0); error_reporting(E_ALL); ini_set('display_errors', '1'); //ini_set('display_errors','Off'); if(!empty($_POST["month"]) ){ $Month=$_POST["month"]; $dealerid = $_POST["dealerid"]; $Mon = date('M', strtotime($Month)); $sql = "select $Mon,Category_Name,Description from revenuetarget WHERE Dealer_ID = '$dealerid'"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_array($result)) { $Category_Name = $row['Category_Name']; $Description = $row['Description']; $Month_Value = $row[$Mon]; $Description1= str_replace(' ', '', $Description); $Category_Name1= str_replace(' ', '', $Category_Name); $result1 = trim($Category_Name1); $result1 .= trim($Description1); $return_arr[] = array( "Category_Name" => $Category_Name, "Description" => $Description, "result" => $result1, "Month_Value" => $Month_Value, ); } $sql = "select * from revenue_data WHERE dealerid = '$dealerid' AND month = '$Month'"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_array($result)) { $Excavator = $row['Excavator']; $Grader= $row['Grader']; $WheelLoader = $row['WheelLoader']; $SLM = $row['SLM']; $Parts_Service_ID = $row['Parts_Service_ID']; $Revanue = $row['Revanue']; $Margin = $row['Margin']; $return_arr1[] = array( "Excavator" => $Excavator, "Grader" => $Grader, "WheelLoader" => $WheelLoader, "SLM" => $SLM, "Parts_Service_ID" => $Parts_Service_ID, "Revanue" => $Revanue, "Margin" => $Margin, ); } //echo json_encode($return_arr); echo json_encode($return_arr1); } ?> I want to display botht the values (Actual and target) on same time. How can i get two array values on same time and display on the table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.