添加"全部"选项进入下拉列表

时间:2015-11-15 12:02:33

标签: php mysql

我在尝试添加" all"时遇到了一些麻烦。选项进入下拉列表(完全在php中制作)。 这是代码:

// SLA list
$sql_loc = "SELECT id, name AS name FROM glpi_slas ".$entidade_sw." 
            ORDER BY `name` ASC ";

$result_loc = $DB->query($sql_loc);

$arr_sla = array();
$arr_sla[0] = "-- ". __('Select a SLA', 'dashboard') . " --" ;

while ($row_result = $DB->fetch_assoc($result_loc))     
{ 
    $v_row_result = $row_result['id'];
    $arr_sla[$v_row_result] = $row_result['name'] ;         
} 

$name = 'sel_sla';
$options = $arr_sla;
$selected = $id_sla;

有谁知道怎么做? 提前谢谢。

P.S。:" all"选项只是选择所有查询结果,而不是一个(就像现在一样)。然后,结果不会仅限于一个SLA。

修改:如何选择'选择SLA1'显示所有门票? (ID可以从1到最后可能[5​​,在这种情况下])

编辑2 :这是选择故障单的代码:

    $sql_cham = 
"SELECT glpi_tickets.id AS id, glpi_tickets.name AS descr, glpi_tickets.date AS date, glpi_tickets.solvedate as solvedate, 
glpi_tickets.status, glpi_tickets.due_date AS duedate, sla_waiting_duration AS slawait, glpi_tickets.type,
FROM_UNIXTIME( UNIX_TIMESTAMP( `glpi_tickets`.`solvedate` ) , '%Y-%m' ) AS date_unix, AVG( glpi_tickets.solve_delay_stat ) AS time,
TIMEDIFF(glpi_tickets.atdate, glpi_tickets.solvedate) AS realtime
FROM glpi_tickets
WHERE glpi_tickets.slas_id = ".$id_sla."
AND glpi_tickets.is_deleted = 0
AND glpi_tickets.date ".$datas2."
AND glpi_tickets.status IN ".$status."
".$entidade."

GROUP BY id DESC
ORDER BY id DESC ";

1 个答案:

答案 0 :(得分:0)

小心,你的/这个SQL不再安全SQL注入

使用它:

"WHERE glpi_tickets.slas_id LIKE ".(empty($id_sla)?'"%"':$id_sla)."
-- instated of this
-- WHERE glpi_tickets.slas_id = ".$id_sla."