如何使用PHP中的复选框按月搜索行?

时间:2017-06-19 16:07:59

标签: php mysql

我尝试使用数组......

    <input type="checkbox" name="mes[]" value="01">January
        <input type="checkbox" name="mes[]" value="02">Feb
        <input type="checkbox" name="mes[]" value="03">March
        <input type="checkbox" name="mes[]" value="04">April
        <input type="checkbox" name="mes[]" value="05">May
        <input type="checkbox" name="mes[]" value="06">June
        <input type="checkbox" name="mes[]" value="07">July
        <input type="checkbox" name="mes[]" value="08">August
        <input type="checkbox" name="mes[]" value="09">September
        <input type="checkbox" name="mes[]" value="10">Oct
        <input type="checkbox" name="mes[]" value="11">Nov
        <input type="checkbox" name="mes[]" value="12">Dec
        <input type="submit" name="reporte_mes">
    </form>

php-mysql代码的一部分:

if(isset($_POST['reporte_mes'])){

$busqueda_cad = implode(',', $_POST["mes"]);

$sql = "SELECT bien_catal.bien, categorias.nombre_categoria, 
marca_catal.marca, color_catal.color, modelo_catal.modelo, 
area_catal.area, condicion.condicion, products.caracteristicas, 
products.stock, products.precio_producto, products.date_added,
products.codigo_producto, products.observaciones FROM products 
LEFT JOIN bien_catal ON (products.fk_bien = bien_catal.id_bien) 
LEFT JOIN categorias ON (products.fk_categoria = categorias.id_categoria)  
LEFT JOIN marca_catal ON (products.fk_marca = marca_catal.id_marca)
LEFT JOIN color_catal ON (products.fk_color = color_catal.id_color)
LEFT JOIN modelo_catal ON (products.fk_modelo = modelo_catal.id_modelo)
LEFT JOIN area_catal ON (products.fk_area = area_catal.id_area)
LEFT JOIN condicion ON (products.fk_condicion = condicion.id_condicion)
WHERE FIND_IN_SET(products.date_added, '$busqueda_cad')";

查询很好,它显示没有WHERE的所有行,但是从WHERE开始,它没有显示任何内容。

1 个答案:

答案 0 :(得分:0)

你的变量$busqueda_cad是几个月的数组吗?因此,WHERE正在查看专栏products.date_added,并尝试将其与一个月匹配?

我认为应该是这样的[COLUMN OF MONTHS]这个列可以保持你的月份当然

WHERE FIND_IN_SET( [COLUMN OF MONTHS] , '$busqueda_cad')";