3
Despite the variable url
be returning content, as VAR_DUMP, the code below comes out by the message "URL nonexistent". Why this? Where am I sinning in the code?
public function getUrlcliente($cliente_id) {
$parametro = "cliente_id=" . (int)$cliente_id;
$url_externa = $this->db->query("SELECT DISTINCT query as indice, keyword as url FROM url_alias WHERE query = '" . $parametro . "'");
if (empty($url_externa)) {
$url = "Erro - URL amigável não cadastrada";
}
else {
foreach ($url_externa as $row) {
var_dump($row);
if (isset($row->url)) {
$pos = strpos($row->url, "www");
if ($pos == false) {
}
else {
$url = $row->url;
break;
}
}
else {
$url = "Url inexistente"; ---> ele está saindo aqui
}
}
}
if ($url_externa->num_rows) {
return $url;
}
else
{
return "Erro-Url inexistente";
}
}
VAR_DUMP is returning this ---->
int(1) array(2) { ["Indice"]=> string(13) "cliente_id=42" ["url"]=> string(21) "http://www.uol.com.br" } array(1) { [0]=> array(2) { [""Indice"]=> string(13) "cliente_id=42" ["url"]=> string(21) "http://www.uol.com.br" } }
Note that the purpose of the function is to return only one string, the URL, not to return an array.
Have you tried to take the amount like this
$row["url"]
?– Augusto
@Augusto was that. Thank you.
– MSergio