POST DATA on Json code for "Autocompleter"

andreasuriani 21 Sep, 2017
Hi All,
i have this problem:

i'm opening a form passed data POST the string [azienda] (is a number code, on this case: 406)
I'm trying to create a Json code for Autocompleter with this data but it doesn't work.
If i print DATAPOST on a form, works fine, but in Json not.

This is my Json code for autocompleter:


<?php
$cod_azie = $_POST['azienda'];
$db = JFactory::getDbo();
$db->setQuery("SELECT  * FROM xcsri_ana_intranet WHERE
cod_azie = $cod_azie
");
$results = $db->loadObjectList();
foreach($results as $result ){
	if(!empty($form->data['tag']) AND stripos($result->nominativo, $form->data['tag']) === false){
		continue;
	}
	$json[] = array('id' => $result->id, 'text' => $result->nominativo);
}
echo json_encode($json);


Any ideas?
andreasuriani 21 Sep, 2017
i forget ot say: if i write $cod_azie = 406; it works........
GreyHead 22 Sep, 2017
Hi andreasuriani,

You haven't defined $json anywhere - that will give a problem with recent PHP versions. Try
$results = $db->loadObjectList();
$json = array();
. . .


Bob
andreasuriani 27 Oct, 2017
Hi Bob,
sorry to be late๐Ÿ˜Ÿ

I've tried but unfortunately doesn't work.


<?php

$cod_azie = $_POST['cod_azie'];
$db = JFactory::getDbo();
$db->setQuery("SELECT  * FROM xcsri_ana_intranet WHERE cod_azie = '" . $cod_azie . "' AND check_conguagliato IS NULL ORDER BY nominativo ASC");
$results = $db->loadObjectList();
$json = array();

foreach($results as $result ){
	if(!empty($form->data['tag']) AND stripos($result->nominativo, $form->data['tag']) === false){
		continue;
	}
	$json[] = array('id' => $result->codice_fiscale, 'text' => $result->nominativo);
}
echo json_encode($json);




Why?๐Ÿ˜Ÿ
GreyHead 27 Oct, 2017
Hi andreasuriani ,

I've no idea, I suggest that you add some debug code to echo out some of your intermediate steps so that you can see exactly what is happening.

Bob
This topic is locked and no more replies can be posted.