-
Notifications
You must be signed in to change notification settings - Fork 10
/
preview.php
56 lines (45 loc) · 1.61 KB
/
preview.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
<?php
include 'includes/session.php';
include 'includes/slugify.php';
$output = array('error'=>false,'list'=>'');
$sql = "SELECT * FROM positions";
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
$position = slugify($row['description']);
$pos_id = $row['id'];
if(isset($_POST[$position])){
if($row['max_vote'] > 1){
if(count($_POST[$position]) > $row['max_vote']){
$output['error'] = true;
$output['message'][] = '<li>You can only choose '.$row['max_vote'].' candidates for '.$row['description'].'</li>';
}
else{
foreach($_POST[$position] as $key => $values){
$sql = "SELECT * FROM candidates WHERE id = '$values'";
$cmquery = $conn->query($sql);
$cmrow = $cmquery->fetch_assoc();
$output['list'] .= "
<div class='row votelist'>
<span class='col-sm-4'><span class='pull-right'><b>".$row['description']." :</b></span></span>
<span class='col-sm-8'>".$cmrow['firstname']." ".$cmrow['lastname']."</span>
</div>
";
}
}
}
else{
$candidate = $_POST[$position];
$sql = "SELECT * FROM candidates WHERE id = '$candidate'";
$csquery = $conn->query($sql);
$csrow = $csquery->fetch_assoc();
$output['list'] .= "
<div class='row votelist'>
<span class='col-sm-4'><span class='pull-right'><b>".$row['description']." :</b></span></span>
<span class='col-sm-8'>".$csrow['firstname']." ".$csrow['lastname']."</span>
</div>
";
}
}
}
echo json_encode($output);
?>