Group repeated data from a given column

Asked

Viewed 152 times

0

I need to select and group the items, but as I have searched, my query will come from a database selected by a variable via post, and I will list the columns that are in a while coming via post from a variable also.

The problem is to group the column that is in while and its results !<br><br> (I add the columns dynamically so I can list "easily" later in select, recording as field1, field2 and so on)

a imaggem pra ter uma ideia

In the case of the image I am selecting by a specific field and not by the variable coming via POST. The product listing, side, etc... ta listed below with the columns named field1, field2, etc.

ex.:

    <p>:: Cadatre a Ultima Compra do Cliente</p>
<?php
    $fila = 'grafica';//$_POST['bd'];
    $pega = $fila.'_lista';
$mostrando = mysql_query("SELECT * FROM $pega order by cod asc " )or die (mysql_error());
    while ($vendo = mysql_fetch_array($mostrando)) {
$campo = $vendo['campo'];

        echo '<div class="_cliente">'.$campo.'</div>';
    }   

    ?>

    <select name="prods" class="input_prod" style="clear: left;">
<?php   
        $prod = mysql_query("SELECT campo1 FROM $fila group by campo1 order by cod asc ") or die(mysql_error());    
    while ($listar = mysql_fetch_array($prod)){

        $campo1 = $listar['campo1'];

        echo '<option value="'.$campo1.'" title="'.$campo1.'">'.$campo1.'</option>';
    }
        ?>

</select>

this example above is as I listed in the sent image, but I need to make a SELECT dynamically.

  • You know how to use jQuery?

  • here the names are without . (point), so there in the other question I edited for column names without point!

  • @Marcelouchimura use jquery practice in all requests!..

  • @Leocaracciolo adjusted the previous answer in the need that had, now ta more complicated the scheme

  • man, I don’t know if it’s viable in your case but you could take in place of dynamic consultations, queries by a larger grouping bringing the mass of data to the application and grouping in the application even... depending on the case it would be possible to play the processing to the client in javascript

No answers

Browser other questions tagged

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