Select "select" values through "GET"

Asked

Viewed 651 times

0

I’m trying and I can’t seem to do the following:

I thought to "automate" the system reporting process that I am doing, for this, when registering the PRODUCT, you also register the column id name and the product id name, thus:

inserir a descrição da imagem aqui

That way I get through GET to define which table, id column, and product name I have to pull. For this, I play all the information in the URL:

inserir a descrição da imagem aqui

So when the person clicked on the product, I already have all the information I need (which table I need to get the information, etc.) through the code below:

    <?php
$produtos = listaProdutos($conexao);
$tabela = $_GET['tabela'];
$coluna = $_GET['coluna'];
$modelo_produto = $_GET['modelo_produto'];
$produtos_id_produto = $_GET['produtos_id_produto'];
$nome_produto = $_GET['nome_produto'];
$sigla_produto = $_GET['sigla_produto'];
?>                  
        <table>
            <tr>
                <td><h3>Qual modelo de <?=$nome_produto?> você deseja anunciar?</h3></td>
                </tr>
        </table>
                <td width="250px" id="anuncios" name="anuncios">
<?php 
$anuncio= mysqli_query($conexao,"SELECT * FROM $tabela order by $modelo_produto");

                echo "<select class='btn btn-link' name='anuncios' id='anuncios'>";
                    while($reg = mysqli_fetch_object($anuncio)){
                echo "<option value='$reg->coluna'>$reg->modelo_produto</option>";
            }
                echo "</select>";
?>      </td>
        <table>
            <tr>

            </tr>
        </table>

And here comes the problem, in the SELECT i can select what i want through the GET with the $table (which informs the table which has to pull the information).

It even works, but when it comes to displaying, it doesn’t show the names:

inserir a descrição da imagem aqui

In the table that must be selected (batteries) are all values:

inserir a descrição da imagem aqui

I believe that he is not able to locate the correct field through the GET that should appear, which in this case is modelo_bateria

I need suggestions on how I can echo the "model_battery field".

 echo "<option value='$reg->coluna'>$reg->modelo_produto</option>";

NOTE: If I change from "modelo_product" to "modelo_battery" it appears with the values correctly:

inserir a descrição da imagem aqui

  • Then try : echo "<option value='$reg->column'>$reg->$modelo_product</option>";

  • When I do this, it does not locate any value, appears "empty" the field of select @Wagnersoares

  • From what I understand the value "model_battery" will come in the variable $modelo_product. That’s not it?

  • What is the structure of the table "batteries" ?

  • @Wagnersoares This, exactly, but when I put this way $modelo_product, it does not appear anything to be selected

  • @AlissonAcioli &#xA;id_bateria / produtos_id_produto / produto_classe / fabricantes_id_fabricante / baterias_familias_id_bateria_familia / modelo_bateria / baterias_tipos_id_bateria_tipo / voltagem_v / capacidade_mah / capacidade_wh /cnx_dtap_pt

Show 1 more comment

1 answer

0

From what you said in the comments, your table structure batteries is:

  • id_bateria
  • products_id_product
  • commodity
  • manufacturer_id_manufacturer
  • baterias_familias_id_bateria_familia
  • modelo_battery
  • battery_type_id_battery_type
  • voltage
  • capability_mah
  • capability_wh cnx_dtap_pt

Your query would be the same as:

"SELECT * FROM baterias order by modelo_bateria"

The problem I think is here:

echo "<option value='$reg->coluna'>$reg->modelo_produto</option>";

For you are trying to return the columns spine and modelo_product, but in its structure it has no, so nothing returns.

Try it like this:

echo "<option value='$reg->$coluna'>$reg->$modelo_produto</option>";

If not, try:

echo "<option value='$reg->{$coluna}'>$reg->{$modelo_produto}</option>";

Browser other questions tagged

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