-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDeck.php
More file actions
56 lines (47 loc) · 1.56 KB
/
createDeck.php
File metadata and controls
56 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
$xml=simplexml_load_file("config.xml");
$servername = $xml -> server;
$username = $xml -> user;
$password = $xml -> password;
$db = $xml -> database;
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$suits = array('H', 'D', 'C', 'S');
$names = array('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K');
for($iS = 0; $iS < count($suits); $iS++)
{
for($iN = 0; $iN < count($names); $iN++)
{
//set value of card based on name
$value = 0;
switch($names[$iN])
{
case 'A':
$value = 1;
break;
case 'J':
case 'Q':
case 'K':
$value = 10;
break;
default;
$value = $iN +1;
break;
}
//build image string
$imageLocation = "./images/" . $names[$iN] . $suits[$iS] . ".png";
//build query string
$sql = "INSERT INTO Cards (CardValue, Suit, CardName, ImageLocation)
VALUES ($value, '$suits[$iS]', '$names[$iN]', '$imageLocation')";
if($conn->query($sql) === TRUE){
echo $suits[$iS] . $names[$iN] . " added";
} else{
echo "Error: " . $sql . "<br />" . $conn->error;
}
}
}
$conn->close();
?>