elicast Posted September 18, 2015 Share Posted September 18, 2015 Caros colegas, tenho um painel de streaming semelhante ao VoxTream que todos mundo aqui acho que já conhece, estou editando todo o codido para PHP Orientado a Objeto, me surgiu uma dificuldade, se alguém puder me ajudar com essa expressão $porta_livre_stm = false; $porta_livre_dj = false; $nova_porta_stm = 6998; $nova_porta_dj = 34998; while(!$porta_livre_stm) { $nova_porta_stm += 2; $total_porta_livre_stm = mysql_num_rows(mysql_query("SELECT * FROM streamings WHERE porta = '".$nova_porta_stm."' ORDER BY porta")); if($total_porta_livre_stm == 0) { $porta_livre_stm = true; } } while(!$porta_livre_dj) { $nova_porta_dj += 2; $total_porta_livre_dj = mysql_num_rows(mysql_query("SELECT * FROM streamings WHERE porta_dj = '".$nova_porta_dj."' ORDER BY porta_dj")); if($total_porta_livre_dj == 0) { $porta_livre_dj = true; } } Acima, ele consulta a menor portas disponível ao cadastrar uma nova radio, Sou intermediário em programação PHP OO, agradeço quem puder dar uma força 0 Quote Link to comment Share on other sites More sharing options...
LucianoZ Posted September 18, 2015 Share Posted September 18, 2015 Que problema você esta tendo, você não especificou, assim fica difícil de ajudar. 0 Quote Chamou? Estamos ai! Link to comment Share on other sites More sharing options...
elicast Posted September 18, 2015 Author Share Posted September 18, 2015 loop infinito, conta todas a portas adicionando mais 2 e não para de contar, sendo que era para para ná primeiro porta que estiver livre com base no menor valor $nova_porta_stm = 6998; 0 Quote Link to comment Share on other sites More sharing options...
evandro Posted September 19, 2015 Share Posted September 19, 2015 Ao invés de contar o total de portas livres. Faça a leitura da maior porta livre e soma +2 a ela. O código vai funcionar e ficar mais rápido assim. 0 Quote Link to comment Share on other sites More sharing options...
elicast Posted September 19, 2015 Author Share Posted September 19, 2015 pode dar um exemplo de de como ficaria... 0 Quote Link to comment Share on other sites More sharing options...
evandro Posted September 19, 2015 Share Posted September 19, 2015 Algo +- assim $porta_livre_stm = mysql_query("SELECT * FROM streamings ORDER BY porta DESC LIMIT 1"); $res_porta_livre_stm = $MySQLi->query($porta_livre_stm) OR trigger_error($MySQLi->error, E_USER_ERROR); while ($item = $res_porta_livre_stm->fetch_object()) { $nova_porta=$item->porta; } $nova_porta_stm = $nova_porta + 2; $porta_livre_dj = mysql_query("SELECT * FROM streamings ORDER BY porta_dj DESC LIMIT 1"); $res_porta_livre_dj = $MySQLi->query($porta_livre_dj) OR trigger_error($MySQLi->error, E_USER_ERROR); while ($item = $res_porta_livre_dj->fetch_object()) { $nova_porta=$item->porta_dj; } $nova_porta_dj = $nova_porta + 2; Com isso automaticamente o código identifica a maior porta e soma 2. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.