Hello all,
I can’t var_dump and I don’t know how to use netbeans debugger (yet).
I’m wondering if someone could help me out.
I want to list all names that are returned on a query, I can only see 1.
The problem can be either on the server side way of processing the results from the database, OR, on the js part. I suppose it’s the first case, but without strong reasons for doing so.
The structure that I have now works for displaying one name.
I want it to work with several names display, when that’s the case.
The js part receives the user input:
1)
function formatar(result) {
return result.nome;
}
$(document).ready(function() {
$('#nomeDominio').autocomplete("searchNome.php", {
cacheLength: 1,
minChars: 3,
parse: function(data)
{
return $.map(eval('('+data+')'), function(result) {
return {
data: result,
value: result.nome,
result: result.nome
}
});
},
formatItem: function(result) {
return formatar(result);
}
});
});
2)
And server side part calls a method on the controller, and encodes
the returned array to be consumed by the javascript:
$keyword = addslashes($_GET["q"]);
$comandos = new ComandoController();
$arr = $comandos->recebeNomeDominios($keyword);
if(is_array($arr))
{
echo json_encode($arr);
}
3)
recebeNomeDominios looks like this:
public function recebeNomeDominios($keyword)
{
$DominioDao = new DominioDao();
$objecto = $DominioDao->recebeNomeDominios($keyword);
return $this->jsonArray($objecto);
}
4)
The object iterated like so:
private function jsonArray($objecto)
{
$json = array();
if(isset($objecto) && !empty($objecto))
{
foreach($objecto as $obj)
{
$json[]["nome"] = $obj;
}
}
return $json;
}
I do believe the issue is here, this works for an object returned by fetch, BUT not with an ARRAY of objects returned by fetchAll.
5)
Finally, I do receive the database returned data, like so:
public function recebeNomeDominios($keyword)
{
$stmt = $this->_dbh->prepare("SELECT d.nomeDominio FROM dominio d WHERE d.nomeDominio LIKE '%".$keyword."%'");
// $stmt->bindParam(1, $nome, PDO::PARAM_STR, 255);
$stmt->execute();
$resultado = $stmt->fetch(PDO::FETCH_OBJ);
return $resultado;
}
This works (the list appear) if we have only 1 returned result, if I change from fetch to fetchAll I got nothing displayed.
Hope I can have your help, at least something to make me moving…
Márcio
note:
I can’t var_dump, nothings get’s displayed on the browser, because we are calling this using an ajax call. If I load directly the controller, I get a white space, no no var_dump there as well…