Although the variable url
is returning content, according to VAR_DUMP, the code below exits the message "URL not existent". Why that? 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) {["index"] = > string (13) "client_id = 42" ["url"] = > string (21) " link "} array (1) {[0] = > array (2) {["index"] = > string (13) "client_id = 42" ["url"] = > string (21) " link "}}
Note that the purpose of the function is to return only one string, the URL, I do not want it to return an array.