Re-char the php function, but it is returning null on the second call

0

What is happening I have this function in pgp that verifies if the url already exists in the database if it already exists it simply adds a number in the front, for this I call the function until it finds one that does not exist example if my-name exists it will try my-name1, my-name2 and return when it works, but the return is only working the first time, already check if the value exists is ok, just not returning.

public function checkUrl($nome,$tabela,$coluna,$cont){
    global $mysql,$fottic; // vairaveis globais
    if($cont > 0){ // veirifca se a função foi chamada novamente
        $url = $nome."-".$cont; // adiciona um numero na url
    }else{ se tiver sido chamada pela prmeiravez normaliza a url
        $url = $fottic->NormalizaURL($nome);
    }
    $qr = mysqli_query($mysql,"SELECT * FROM $tabela WHERE $coluna='$url'") or die(mysql_error()); // verifica no db se existe
    if(mysqli_num_rows($qr) == '0'){
        return $url; // se não existe retorna o valor

    }else{
        $cont++;
        $fottic->checkUrl($url,$tabela,$coluna,$cont);
        //se já existe, faz toda função novamente
    }
}
    
asked by anonymous 19.07.2016 / 16:19

1 answer

1

I was able to find what went wrong, had to return the function again

}else{
    $cont++;
    return  $fottic->checkUrl($url,$tabela,$coluna,$cont);
    //se já existe, faz toda função novamente
}
    
19.07.2016 / 16:29