function mysql_query_2select_multiple($sql, $value, $text, $first_option_text = '', $attr = '', $reporte_id)
{
    mysql_select_db(DB_NAME);
    if (!empty($reporte_id) && !empty($value)) {
        $filtro = "select VALOR from rep_p_reportes_detalle where REPORTE_ID=" . $reporte_id . " and CAMPO='" . $value . "'";
        $fil = mysql_query($filtro);
        while ($row = mysql_fetch_array($fil)) {
            $arreglo = explode(',', $row['VALOR']);
            $cc++;
        }
    }
    $sql .= " ORDER BY {$text} ASC";
    $result = total_query($sql, 1);
    $attr = $attr == '' ? "name='{$value}' id='{$value}'" : $attr;
    $first_option_text = $first_option_text == '' ? str_replace("_ID", "", $value) . "..." : $first_option_text;
    $select = '<select ' . $attr . ' >';
    $select .= $first_option_text != "" ? '<option value="">' . $first_option_text . '</option>' : '';
    while ($row = mysql_fetch_assoc($result)) {
        if (!empty($reporte_id) && $cc > 0) {
            if (in_array($row[$value], $arreglo)) {
                $select .= '<option selected="selected" value="' . $row[$value] . '">' . $row[$text] . '</option>';
            } else {
                $select .= '<option value="' . $row[$value] . '">' . $row[$text] . '</option>';
            }
        } else {
            $select .= '<option value="' . $row[$value] . '">' . $row[$text] . '</option>';
        }
    }
    $select .= '</select>';
    return $select;
}
예제 #2
0
        }
        if ($c > 0) {
            $data = substr($data, 0, strlen($data) - 1);
        }
        //le quita la ultima coma;
        $data .= '},';
    }
    if (mysql_num_rows($result) > 0) {
        $data = substr($data, 0, strlen($data) - 1);
    }
    //le quita la ultima coma
    echo '{"DATOS":[' . $data . ']}';
} else {
    if (!empty($ids) && !empty($sql)) {
        $sql = str_replace('$ids', $ids, $sql);
        $result = total_query($sql);
        while ($row = mysql_fetch_assoc($result)) {
            $data .= '{';
            $c = 0;
            foreach ($row as $key => $value) {
                $c++;
                $data .= '"' . $key . '":"' . $value . '",';
            }
            if ($c > 0) {
                $data = substr($data, 0, strlen($data) - 1);
            }
            //le quita la ultima coma;
            $data .= '},';
        }
        if (mysql_num_rows($result) > 0) {
            $data = substr($data, 0, strlen($data) - 1);
예제 #3
0
/**
 * creates a select element from a query
 * @param string $sql
 * @param string $value
 * @param string $text
 * @param string $first_option_text
 * @param string $attr
 * @return string
 */
function mysql_query_2select($sql, $value, $text, $first_option_text = '', $attr = '')
{
    $sql .= " ORDER BY {$text} ASC";
    $result = total_query($sql, 1);
    $attr = $attr == '' ? "name='{$value}' id='{$value}'" : $attr;
    $first_option_text = $first_option_text == '' ? str_replace("_ID", "", $value) . "..." : $first_option_text;
    $select = '<select ' . $attr . ' >';
    $select .= $first_option_text != "" ? '<option value="">' . $first_option_text . '</option>' : '';
    while ($row = mysql_fetch_assoc($result)) {
        $select .= '<option value="' . $row[$value] . '">' . $row[$text] . '</option>';
    }
    $select .= '</select>';
    return $select;
}