how to get entire array from ajax call instead of single val from sqlVal()

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
Veteran Member
Posts: 84
Joined: 2018-03-04 09:30

how to get entire array from ajax call instead of single val from sqlVal()

Post by D Oliveira » 2019-09-10 22:56

Code: Select all


$j('#ID').change(function(){

		p3 = $j('#ID').val();

					$j.ajax({
						url: 'hooks/ajax-copiadieta.php',
						data: { p: p3 },
						success: function(data){
							if (data) {

								console.log(data);
								$j('#ID2').val(data);

								
							}else{
							
								console.log('nodata');

							}
						}
					});

	});

Code: Select all


$p = makesafe($_REQUEST['p']);

$sql = "SELECT ID FROM dietasuplib_new WHERE ID = '{$p}'";

$data1 = sqlValue($sql);

echo $data1;

how to return the entire array * from dietasuplib_new instead of single value using sqlVal() function?

User avatar
D Oliveira
Veteran Member
Posts: 84
Joined: 2018-03-04 09:30

Re: how to get entire array from ajax call instead of single val from sqlVal()

Post by D Oliveira » 2019-09-11 00:11

found the solution.

Code: Select all

$j('#imp-container').change(function(){

		valor_entidad3 = $j('#imp-container').val();

			$j.ajax({
				url: 'hooks/ajax-copiadieta.php',
				data: { entidad_id: valor_entidad3 },
				success: function(data){
					if (data) {
						var tbl = jQuery.parseJSON(data)
						console.log(tbl);
						AppGini.current_id1_1.value=tbl.id1;
						id1_1_reload();
						$j('#desc1_1').val(tbl.desc1);
						$j('#cal1_1').val(tbl.cal1);
						$j('#fat1_1').val(tbl.fat1);


						
					}else{
						//console.log('nodata');
					}

					

				}
			});



	});

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	/* grant access to all users who have acess to the orders table */
	//db connection
	require ('../config.php');

	$entidad = makesafe($_REQUEST['entidad_id']);

	$con = mysqli_connect($dbServer, $dbUsername, $dbPassword);
	mysqli_select_db($con,$dbDatabase);

	$query = mysqli_query($con,"select * from dietasuplib_new where ID= '{$entidad}'");
	$dietasuplib_new = mysqli_fetch_array($query);

    echo json_encode($dietasuplib_new);
?>

Post Reply