Hi, I've got the following mysql table (expensemonthly):
I'm trying to fill inputs text in a form with the account_id (and account name fetch from another mysql table called "accounts"), for doing that from ajax code below I call a php file (CountFetchExpensesArrayDos.php) for creating a two dimention array:
Below the CountFetchExpensesArrayDos.php file for getting data from the month (112021):
My problem is that when data is arriving to ajax in an unknown format, If show data "alert(data);" I see it comma separated, but I cannot splitted using javascript "split() Method", I need to split data receive for filling Inputs in the form, this the data as received in ajax:
Please any Ideas? If is there another method to get data from month using php and pass it to Ajax?
I'm trying to fill inputs text in a form with the account_id (and account name fetch from another mysql table called "accounts"), for doing that from ajax code below I call a php file (CountFetchExpensesArrayDos.php) for creating a two dimention array:
Code:
//Count Registers and Fill Inputs
$('#count').click(function(){
$.ajax({
url:"CountFetchExpensesArrayDos.php",
method: 'POST',
dataType: 'json',
data:{monthyear:"112021"},
success:function(data){
// array Receive
alert(data);
AddInputs(data.count);
alert("Se detectaron: "+data+" registros");
FillExpensesInputs(data.count,data.account_id,data.name);
}
});
});
PHP:
$Month = $connect->real_escape_string($_POST['monthyear']);
//Count number of month registers
$sqlc = $connect->query("SELECT * FROM expensemonthly WHERE yearmonth = '$Month'");
$count=$sqlc->num_rows;
if(! $connect ) {
die('Could not connect: ' . mysqli_error());
}
//Get account_id and name for the month registers
$sql = "SELECT * FROM expensemonthly,accounts WHERE yearmonth = '$Month' AND accounts.account_id=expensemonthly.account_id";
$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
$final_array = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$final_array[] = $row['account_id'];
$final_array[] = $row['name'];
}
$CountArray[] = $count;
//Merge Array with number of register for the month, account_id,name
$Totalarray = array_merge($CountArray,$final_array);
//Send array to ajax
exit(json_encode($Totalarray));
} else {
echo "0 results";
}
mysqli_close($connect);
My problem is that when data is arriving to ajax in an unknown format, If show data "alert(data);" I see it comma separated, but I cannot splitted using javascript "split() Method", I need to split data receive for filling Inputs in the form, this the data as received in ajax:
Please any Ideas? If is there another method to get data from month using php and pass it to Ajax?