-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
80 lines (80 loc) · 3.05 KB
/
index.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
<?php
$servername = "localhost";
$username = "user";
$password = "password";
$dbname = "Shopping";
$data=array();
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, 0, '/path/to/mysql/socket');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Checked, Item, Shop FROM List where display =1 order by Shop, Item";
$result = $conn->query($sql);
//Set width to work properly on a phone
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
//Start of main table to display data
echo '<big>Listy McListface</big><br>';
echo '<table border=1><tr><th>Ticked</th><th>Item</th><th>Shop</th></tr>';
//Set up a post so that it can write ticks to the database
echo '<form action="https://path/to/checks.php" method="POST">';
// output data of each row
while($row = $result->fetch_assoc()) {
//Add a double row if shop changes
$curshop=$row['Shop'];
if ($lastshop!=$curshop){
echo "<tr><td></td><td></td><td></td></tr>";
}
$lastshop=$row['Shop'];
echo "<tr align=center><td>";
//Show checked state based on database
$checked = '';
if($row['Checked'] == TRUE){
$checked = 'checked';
}
$item=$row['Item'];
//Checks go into an array with the name of the item so it can be matched
echo '<input type="checkbox" value="'.$item.'" name="chk[]"'.$checked.'>';
echo "</td><td>";
echo $row['Item'];
echo "</td><td>";
echo $row['Shop'];
echo "</td></tr>";
}
echo '</table>';
echo '<input type="submit" value="Save Ticks"></form><br>';
//Refresh
echo '<form action ="https://path/to/index.php" method="GET">';
echo '<input type="submit" value="Refresh">';
echo '</form>';
//New entry insert form
echo '<form action="https://path/to/inserto.php">';
echo 'Item <input type="text" name="Item">';
//Get list of names from the table and display in order
$sql = "SELECT Name FROM Shops order by Number";
$result = $conn->query($sql);
//yes I put them in a table after all so almost as many lines as a static list
echo '<select name="Shop">';
while($row = $result->fetch_assoc()) {
echo '<option value="';
echo $row['Name'];
echo '">';
echo $row['Name'];
echo '</option>';
}
echo '</select><br>';
echo '<input type="submit" value="Add item">';
echo '</form>';
//Remove the ticked items from the displayed list.
echo '<form action ="https://path/to/remticked.php" method="POST">';
echo 'Save ticks before removing<br>';
echo '<input type="submit" value="Remove Ticked">';
echo '</form>';
//Crude undo last so many minutes
echo '<form action ="https://path/to/undo.php" method="POST">';
echo 'Undo recent removes<br>';
echo '<input type="submit" value="Undo Removes">';
echo '</form>';
$conn->close();
?>