How to do in a select html, when clicking select more than one row at a time?

5

I have a query that brings me the first 3 letters of the name of a month with the last two digits of the year for example: JAN.16 in my combobox it brings me months independent for example: JAN.16 FEV.16 ... and on and on.

I wanted the combobox or click on JAN.16 also get FEV.16 and MAR.16, in 3 in 3 months or make a block of those 3 months in the combobox that value of the combobox, I get the database with the query below

select mes from tabela where mes in ('JAN.16');
select mes from tabela where mes in ('FEV.16');... e por ai vai chegar DEZ.16.

I tried this way, also the information was not replicated:

select mes from tabela where (mes like 'JAN.%' or mes like 'FEV.%' or mes like 'MAR.%');

$q1 = mysql_query("select distinct mes from reparo.falhas_consolidadas where mes like 'JAN%' or mes like 'FEV%' or mes like 'MAR%'");

<td><select multiple name="month[]" id="month">
        <option value="">Selecione</option>
            <?php 
                    while($m1 = mysql_fetch_array($q1)){
                        echo "<option value='$m1[0]'>Q1</option>";
                    }
            ?>      
</select>

What it replicates is option , but it is because of while , what I would like is option to get the value of months, this value is in different rows.

    
asked by anonymous 08.06.2016 / 17:39

2 answers

0

I did not exactly understand the part of the selection how it should work, explain better that I edit my answer if necessary.

But regarding the search in the bank, just do the following:

select mes from tabela where mes in ('JAN.16', 'FEV.16', 'MAR.16');

You can either send the 3 separate values to PHP like send a string and give an explode in PHP.

    
09.06.2016 / 00:43
0

Well, I understand why you want to take a month and get the next 2 months? Well you can start then by seeing the value you are assigning to your option.

Let's say you have 3 options

<option value = 1 >JAN.16</option>
<option value = 2 >FEV.16</option>
<option value = 3 >MAR.16</option>

You can send via one form per post or Get your value, ie 1, 2 or 3 in this case. And you send another value that will be your value + 2 to know where it ends.

You receive this in your php file where you are doing the sql and you will give select per mesId $ i = $ valueoriginal;  or what you click and you send the form

select mes from tabela where mesid in ( for($i;$i<=$valorqueagentesomou;$i++) {

if ($i<$valorqueagentesomou)
{
'.$i.";".'
}
else {
.'$i'.
}

}

);
    
09.06.2016 / 01:07