Esempio n. 1
0
 public function getTag()
 {
     $tmp = $this->field('tag')->distinct(true)->select();
     $tmp = tran2Array($tmp, $index = 'tag');
     $tag_lump = array();
     foreach ($tmp as $value) {
         $tmp_arr = getArray($value);
         $tag_lump = array_merge($tag_lump, $tmp_arr);
     }
     // p($tag_lump);
     $tag_lump = array_unique($tag_lump);
     // pd($tag_lump);
     return $tag_lump;
 }
Esempio n. 2
0
function addAllSql($store_db_name, $matrix, $field = null, $db_prefix = '')
{
    // (empty($matrix))&&(E('matrix is empty'));
    if (empty($matrix)) {
        echo 'fail inserting at ', time(), '<br/>';
        return false;
    }
    !checkIfMatrix($matrix) && E('matrix\'s format is wrong');
    //data_array应该是一个二维数组
    $Model = new \Think\Model();
    $sql_comm = 'show columns from ' . $store_db_name;
    $column_info_matrix = $Model->query($sql_comm);
    $column_info_array = tran2Array($column_info_matrix, 'field');
    /*按照field过滤下matrix-->data_matrix*/
    $data_matrix = array();
    if ($field !== null) {
        /*field_combine为二者交集*/
        $field_combine = array();
        foreach ($field as $key => $value) {
            if (in_array($value, $column_info_array)) {
                $field_combine[] = $value;
            }
        }
    } else {
        $field_combine = $column_info_array;
    }
    $data_matrix = fieldMatrix($matrix, $field_combine);
    foreach ($data_matrix as $key => $data_array) {
        foreach ($data_array as $key_lv2 => $value) {
            $data_array_tmp[$key_lv2] = "'" . $value . "'";
        }
        $insert_data_string_row[] = '(' . implode(',', $data_array_tmp) . ')';
    }
    $insert_data_string = implode(',', $insert_data_string_row);
    foreach ($data_matrix as $key => $value) {
        //得到col_name
        $col_array = array_keys($value);
        break;
    }
    $col_string = '`' . implode('`,`', $col_array) . '`';
    $sql_comm = "insert into `" . $db_prefix . $store_db_name . "` (" . $col_string . ") VALUES" . $insert_data_string;
    // pd($sql_comm);
    return $Model->execute($sql_comm);
}