-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullQuestions.php
94 lines (76 loc) · 2.94 KB
/
pullQuestions.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
$con=mysqli_connect("localhost","root","root","popture");
//$con=mysqli_connect("sabrihack.db.4286364.hostedresource.com","sabrihack","P0ptur3!","sabrihack");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$question = array();
$slot1 = $_POST["slot1"];
$slot2 = $_POST["slot2"];
$slot3 = $_POST["slot3"];
// find questions with all three celebs
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot1.",".$slot2.",".$slot3."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with combos of first two celebs
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot1.",".$slot2."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with combos of last two celebs
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot2.",".$slot3."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with combos of first and last two celebs
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot1.",".$slot3."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with first celeb
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot1."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with second celeb
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot2."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
// find questions with last celeb
$sql = "SELECT questionid, question FROM questions WHERE ";
$sql .= "celebrities = '".$slot3."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$questionId = $row['questionid'];
$question[ $questionId ] = $row['question'];
}
mysqli_close($con);
if($question){
$questionId = array_rand($question); //select one random question from all possible choices
echo $question[$questionId];
echo "<script>$('.question').attr('id',".$questionId.");</script>";
} else {
echo "no question found <script>$('#spin').toggle();$('#submit_answer').toggle();$('body').on('click', '.celeb', selectAnswer);</script>";
}
?>