Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By userg19
#830438
I have a code that load sql data that sum the value but i want to get the different column on sql to call on javascript


("#monthofdatawfr").getControl()[0].multiple = true
$('#monthofdatawfr').click(function(){
let dataval = '';

$('#monthofdatawfr option:selected').each(function(){
dataval = (dataval*1);
dataval += +$(this).val();

$("#textVar078").setValue(dataval); // same value
$("#quota1").setValue(dataval); //same value but need to setValue on my other column on sql
});

});
By thomas32
#830465
You could use ajax to make a call to the server and retrieve the other column's value.

Assuming you have a server-side script that can provide the value, you could do something like this:

$('#monthofdatawfr').click(function(){
let dataval = '';

$('#monthofdatawfr option:selected').each(function(){
dataval = (dataval*1);
dataval += +$(this).val();

$("#textVar078").setValue(dataval); // same value

// Make an ajax call to retrieve the other column's value
$.ajax({
url: 'yourscript.php',
type: 'GET',
data: { value: dataval },
success: function(data) {
$("#quota1").setValue(data); // setValue on my other column on sql
}
});
});

});
By celinedion
#830592
you can use AJAX to send an HTTP request to a server-side script (e.g. PHP) that updates the SQL database based on the selected option(s). Here's an example of how you can modify your code:

$("#monthofdatawfr").getControl()[0].multiple = true;

$('#monthofdatawfr').click(function() {
let dataval = 0;

$('#monthofdatawfr option:selected').each(function() {
dataval += parseFloat($(this).val());
});

$("#textVar078").setValue(dataval);
$("#quota1").setValue(dataval);

// Send an HTTP request to update the SQL database
$.ajax({
url: 'update_sql.php',
method: 'POST',
data: {quota1_value: dataval},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.log(error);
}
});
});

In the above code, update_sql.php is a server-side script that updates the SQL database based on the value of quota1_value that is passed in the HTTP request. You need to implement the update_sql.php script to connect to your SQL database and update the relevant column(s).
User avatar
By raavikant
#830802
Hi,

To achieve this, you need to modify the code to fetch the required column value from the SQL database.

Here's an outline of what you may need to do:

Create a Server-Side Endpoint to Fetch Data: Write a server-side script (e.g., PHP, Node.js) to connect to the SQL database, execute the required query, and fetch the desired column value.

Call the Server-Side Endpoint from JavaScript: Make an AJAX request from your JavaScript code to call the server-side endpoint and retrieve the required value.

Modify the Value in JavaScript: Use the retrieved value to set the value of the element with the ID quota1.

Here's a code snippet that might fit into your existing code:

JS-
Code: Select all
$('#monthofdatawfr').click(function(){
  let dataval = '';

  $('#monthofdatawfr option:selected').each(function(){
    dataval = (dataval*1);
    dataval += +$(this).val();
  });

  // Setting the first value as usual
  $("#textVar078").setValue(dataval);

  // Making an AJAX request to get the other column value from SQL
  $.get('path/to/your/server/endpoint', { data: dataval }, function(response) {
    // Assuming the response contains the value for the 'quota1' field
    $("#quota1").setValue(response.quotaValue);
  });
});

Make sure to replace 'path/to/your/server/endpoint' with the actual URL of your server-side script that retrieves the required column value from the SQL database.
By jaggedswift
#830965
raavikant wrote: Wed Aug 09, 2023 6:56 am Hi,

To achieve this, you need to modify the code to fetch the required column value from the SQL database.

Here's an outline of what you may need to do:

Create a Server-Side Endpoint to Fetch Data: Write a server-side script (e.g., PHP, Node.js) to connect to the SQL database, execute the required query, and fetch the desired column value.

Call the Server-Side Endpoint from JavaScript: Make an AJAX request from your JavaScript code to call the server-side endpoint and retrieve the required value.

Modify the Value in JavaScript: Use the retrieved value to set the value of the element with the ID quota1.

Here's a code snippet that might fit into your existing code:

JS-
Code: Select all
$('#monthofdatawfr').click(function(){
  let dataval = '';

  $('#monthofdatawfr option:selected').each(function(){
    dataval = (dataval*1);
    dataval += +$(this).val();
  });

  // Setting the first value as usual
  $("#textVar078").setValue(dataval);

  // Making an AJAX request to get the other column value from SQL
  $.get('path/to/your/server/endpoint', { data: dataval }, function(response) {
    // Assuming the response contains the value for the 'quota1' field
    $("#quota1").setValue(response.quotaValue);
  });
});

Make sure to replace 'path/to/your/server/endpoint' with the actual URL of your server-side script that retrieves the required column value from the SQL database.
It's worked, many thanks.

Yes, you can restrict your PDF file from copying t[…]

Attention crypto enthusiasts! Are you ready to div[…]

Xanaxgeneric.com is the top online pharmacy in the[…]

Buy Xanax Online is an FDA-approved medication tha[…]