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

Asked

Viewed 688 times

6

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

I wanted the combobox or click on JAN.16 take also FEB.16 and MAR.16, in 3 in 3 months or make a block of those 3 months in the combobox that combobox value, I take from 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 that way, it wasn’t replicated the information either:

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

take those 3 months only that in the combobox appeared only one information someone knows if it has how to do it?

$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 replicates is the option, but it’s because of while, what I would like is a option to take the value of months, this value is in different lines.

  • Could you post more information? What replicates? What does not work? Where the combobox enters?

  • Wouldn’t just put the three of us on the option? <option>Jan Fev Mar</option>

3 answers

1

Please see if what you want to solve like this:

SELECT GROUP_CONCAT( `mes` SEPARATOR ', ' ) `mes`
FROM   `tabela`
WHERE  `mes` IN('JAN.16', 'FEV.16', 'MAR.16');

1

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

But as far as the bank search goes,:

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

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

1

Well from what I understand, you want to take a month and take the next two months ? Well you can start by seeing the value you’re assigning to your option.

Let’s say you have three options

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

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

You get this in your php file where you are doing sql and you will give select by mesId $i= $valueoriginal; or whatever you click and send yourself by the form

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

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

}

);

Browser other questions tagged

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