示例#1
0
function insert_card_to_deck($table, $card)
{
    global $CARD_TABLE_NAME, $CARD_VALID_ID_CONSTRAINT;
    foreach ($card as $name => $num) {
        #$query = "SELECT id FROM $CARD_TABLE_NAME WHERE name = \"$name\" AND id RLIKE '[0-9_][0-9]$';";
        $query = "SELECT id FROM {$CARD_TABLE_NAME} WHERE name = \"{$name}\" AND {$CARD_VALID_ID_CONSTRAINT};";
        #echo $query;
        #echo "<br>";
        $result = mysql_query($query);
        $count = @mysql_numrows($result);
        check_single_tuple($count, $name);
        #if ($count != 1) {
        #    error_msg("multiple($count) \"$name\"");
        #    #echo "ERROR: multiple $name";
        #    #echo "<br>"
        #}
        $id = mysql_result($result, 0, "id");
        #echo "id: $id, num: $num";
        #echo "<br>";
        $tuple = array();
        $tuple["id"] = $id;
        $tuple["num"] = $num;
        $query = mysql_insert_str($table, $tuple);
        #echo $query;
        #echo "<br>";
        exec_mysql_query($query);
    }
}
示例#2
0
function insert_card_data($table, $arr)
{
    foreach ($arr as $set_type => $card_obj) {
        $card_array = (array) $card_obj;
        foreach ($card_array as $set_seq => $card_info_obj) {
            $data = array();
            $data["setType"] = $set_type;
            $data["setSeq"] = $set_seq;
            $card_info_array = (array) $card_info_obj;
            foreach ($card_info_array as $key => $value) {
                $value_type = gettype($value);
                $value_all = "";
                if ($value_type == "array") {
                    $value_all = implode(', ', $value);
                } else {
                    if ($value_type == "object") {
                        $value_all = implode(', ', (array) $value);
                    } else {
                        if ($value === false) {
                            $value_all = 0;
                        } else {
                            $value_all = $value;
                        }
                    }
                }
                #echo "setType=$set_type, setSeq=$set_seq";
                #echo "<br>";
                $data[$key] = mysql_real_escape_string($value_all);
            }
            $query = mysql_insert_str($table, $data);
            #echo $query;
            #echo "<br>";
            exec_mysql_query($query);
            #if ($data["id"] == "EX1_066") {
            #    exec_mysql_query($query);
            #}
        }
    }
}