好吧,所以我以前从未这样做过。我不是专业人士,但我大致了解MySQL的工作原理。我知道我的方式稍微好一点,但仍然是初学阶段。我目前还有一种方法可以解决它。
然而,在我浪费2个多小时学习我做错了之前,我想我先问你们这些人会怎么做。我从一个(相对)小阵列开始,并在我理解得很好的时候努力工作。
数组:http://pastebin.com/g8RyxtP5
那么......你会怎样做到MySQL?现在我最初的想法是让桌子现在看起来像这样:
<?php
include "login.php";
include "createdb.php";
$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_table)
or die("Some error occurred during connection " . mysqli_error($con));
/*$sql = "CREATE TABLE Career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Username varchar(32),
Password varchar(32),
Battletag varchar(32),
Region varchar(2)
)
";*/
$sql = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(32),
lastHeroPlayed varchar(32),
lastUpdated varchar(32),
monsters varchar(32),
elites varchar(32),
hardcoreMonsters varchar(32),
barbarian varchar(32),
crusader varchar(32),
demon-hunter varchar(32),
monk varchar(32),
witch-doctor varchar(32),
wizard varchar(32),
paragonLevel varchar(32),
paragonLevelHardcore varchar(32),
h1name varchar(32),
h1id varchar(32),
h1level varchar(32),
h1hardcore varchar(32),
h1gender varchar(32),
h1dead varchar(32),
h1class varchar(32),
h1last-updated varchar(32),
h2name varchar(32),
h2id varchar(32),
h2level varchar(32),
h2hardcore varchar(32),
h2gender varchar(32),
h2dead varchar(32),
h2class varchar(32),
h2last-updated varchar(32),
h3name varchar(32),
h3id varchar(32),
h3level varchar(32),
h3hardcore varchar(32),
h3gender varchar(32),
h3dead varchar(32),
h3class varchar(32),
h3last-updated varchar(32),
h4name varchar(32),
h4id varchar(32),
h4level varchar(32),
h4hardcore varchar(32),
h4gender varchar(32),
h4dead varchar(32),
h4class varchar(32),
h4last-updated varchar(32),
h5name varchar(32),
h5id varchar(32),
h5level varchar(32),
h5hardcore varchar(32),
h5gender varchar(32),
h5dead varchar(32),
h5class varchar(32),
h5last-updated varchar(32),
h6name varchar(32),
h6id varchar(32),
h6level varchar(32),
h6hardcore varchar(32),
h6gender varchar(32),
h6dead varchar(32),
h6class varchar(32),
h6last-updated varchar(32),
h7name varchar(32),
h7id varchar(32),
h7level varchar(32),
h7hardcore varchar(32),
h7gender varchar(32),
h7dead varchar(32),
h7class varchar(32),
h7last-updated varchar(32),
h8name varchar(32),
h8id varchar(32),
h8level varchar(32),
h8hardcore varchar(32),
h8gender varchar(32),
h8dead varchar(32),
h8class varchar(32),
h8last-updated varchar(32),
h9name varchar(32),
h9id varchar(32),
h9level varchar(32),
h9hardcore varchar(32),
h9gender varchar(32),
h9dead varchar(32),
h9class varchar(32),
h9last-updated varchar(32),
h10name varchar(32),
h10id varchar(32),
h10level varchar(32),
h10hardcore varchar(32),
h10gender varchar(32),
h10dead varchar(32),
h10class varchar(32),
h10last-updated varchar(32),
h11name varchar(32),
h11id varchar(32),
h11level varchar(32),
h11hardcore varchar(32),
h11gender varchar(32),
h11dead varchar(32),
h11class varchar(32),
h11last-updated varchar(32),
h12name varchar(32),
h12id varchar(32),
h12level varchar(32),
h12hardcore varchar(32),
h12gender varchar(32),
h12dead varchar(32),
h12class varchar(32),
h12last-updated varchar(32),
";
if (mysqli_query($con,$sql)) {
echo "TABLE 'Career' created successfully!<br>";
} else {
echo "Error creating table: " . mysqli_error($con)."<br>";
}
mysqli_query($con, $sql);
在创建表之后,我将做一些PHP / MySQL魔术(基本上就像我去的那样学习)以获得array-&gt; parse-&gt;推送到mysql?
感谢您的任何见解。 我应该做什么/我应该怎么做呢?
编辑:好吧我想也许我可以让一张桌子还可以,并将定义的职业变形“战斗标签”分别包含在每个英雄中(以及每个英雄需要的任何重要信息)。我认为这比我的工作效果更好。
$sql = "CREATE TABLE heros (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(64) ,
name varchar(32),
id int,
level int,
hardcore bool,
gender bool,
dead bool,
class varchar(32),
last-updated TIMESTAMP
";
$sql2 = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(64),
lastHeroPlayed varchar(32),
lastUpdated TIMESTAMP,
monsters int,
elites int,
hardcoreMonsters int,
barbarian DOUBLE(4,3),
crusader DOUBLE(4,3),
demon-hunter DOUBLE(4,3),
monk DOUBLE(4,3),
witch-doctor DOUBLE(4,3),
wizard DOUBLE(4,3),
paragonLevel int,
paragonLevelHardcore int
";
答案 0 :(得分:1)
从1到12 ......
h12name varchar(32),
h12id varchar(32),
h12level varchar(32),
h12hardcore varchar(32),
h12gender varchar(32),
h12dead varchar(32),
h12class varchar(32),
h12last-updated varchar(32),
以下可以是1列&#34; GAME_NAME&#34;所以你仍然可以添加......
$sql = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(32),
lastHeroPlayed varchar(32),
lastUpdated varchar(32),
monsters varchar(32),
elites varchar(32),
hardcoreMonsters varchar(32),
barbarian varchar(32),
crusader varchar(32),
demon-hunter varchar(32),
monk varchar(32),
witch-doctor varchar(32),
wizard varchar(32),
paragonLevel varchar(32),
paragonLevelHardcore varchar(32),
我建议只创建这样的表...或者你可以为游戏创建2个连接表1,为hnn创建一个...
name_game varchar(150)
hname varchar(32),
hid varchar(32),
hlevel varchar(32),
hhardcore varchar(32),
hgender varchar(32),
hdead varchar(32),
hclass varchar(32),
hlast-updated varchar(32),
冗余只需放入1个表..............