Jump to content

Converter para PHP OO


Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...

Important Information

Do you agree with our terms?