UPDATE Mysql PHP

Asked

Viewed 80 times

0

I have a website in 3 languages. PT-EN-ES. The customer always registers the information in PT first. After that add the other languages.

DOUBT:

In the control panel has the option to ADD these other 2 languages as in the image inserir a descrição da imagem aqui Database

id   |   produto_id   |   idioma
1    |   522          |   1
2    |   522          |   2
3    |   522          |   3

Language: PT = 1, EN = 2 and ES = 3

When I register, the ID 1 appears, which is what I registered. I need to register the other 2.

How to make a select in the bank to get the q I registered?

Product (such ID) with LANGUAGE (such)

How do I select USING PDO

And if you don’t have the registered language, the registration button appears, if you have registered, one button appears to edit and the other to delete

Follow the code I’m using

<?php if ($listar->rowCount($dados->idioma) < 2) {?>
    <td>
    <a href="painel.php?p=produtos-idiomas-cadastrar&cod=<?php echo $dados->id_produto; ?>&img=<?php echo $dados->produto_imagem; ?>&cat=<?php echo $dados->categoria; ?>&idioma=2">
    <button type="submit" class="btn btn-success"><i class="fa fa-plus"></i> Cadastrar</button>
    </a>
    </td>
<?php } else {
    $listar2 = $pdo->prepare("SELECT * FROM produtos WHERE ativo = 1 AND id_produto = :cod AND idioma = 2");
    $listar2->bindParam(':cod', $cod);
    $listar2->execute();
    $dados2 = $listar2->fetch(PDO::FETCH_OBJ);
?>
    <td>
        <a href="painel.php?p=produtos-idioma-editar&cod=<?php echo $dados2->id;?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true" title="Editar"></span></a> <a href="produtos-deletar.php?cod=<?php echo $dados2->id;?>"><span class="glyphicon glyphicon-remove" aria-hidden="true" title="Editar"></span></a>
    </td>
<?php } ?>

I do the same thing with ES changing only the idioma para 3.

  • 1

    I don’t know if I understand this correctly, but are you doing a select for each language?? If so, wouldn’t it be easier to select first with the product code, and then with the while loop check which languages exist? ,making a treatment of what will be displayed on the screen?

  • That’s exactly what I did... and it worked... vlw

  • Opa blz, tamo together ^^

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.