-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
59 lines (50 loc) · 2.56 KB
/
index.php
File metadata and controls
59 lines (50 loc) · 2.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
57
58
59
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center><h1>CMU Questions</h1><center>
<?php
$category = $_GET['category'];
if($category)
{
# This function reads your DATABASE_URL config var and returns a connection
# string suitable for pg_connect. Put this in your app.
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}
# Here we establish the connection. Yes, that's all.
$db = pg_connect(pg_connection_string_from_database_url());
# Now let's use the connection for something silly just to prove it works:
$result1 = pg_query($db, "SELECT relname FROM pg_stat_user_tables WHERE schemaname='public' ORDER BY RELNAME");
if (!pg_num_rows($result1)) {
print("Your connection is working, but your database is empty.\nFret not. This is expected for new apps.\n");
} else {
while ($row = pg_fetch_row($result1)) {
if (!($row[0] == "main" or $row[0] == "users" or substr($row[0],-2) != $category)){
$tableNo=substr($row[0],3);
$sql="SELECT name FROM MAIN WHERE id=".$tableNo." ORDER BY ID";
$result = pg_query($db, $sql);
$arr = pg_fetch_all($result);
print_r("<center><h2><a href='/view.php?id=".$tableNo."'>".$arr[0]['name']."</a></h2></center><br>");
}
}
}
// echo '<h1>MAIN:</h1>';
// $result = pg_query($db, "SELECT ID, NAME FROM MAIN ORDER BY ID DESC LIMIT 1000");
// $arr = pg_fetch_all($result);
// print_r(array_values($arr));
pg_close($db);
}
else
{
if(isset($_POST))
{?>
<h2><a href = 'index.php?category=00'>Food</a></h2><br>
<h2><a href = 'index.php?category=01'>Places</a></h2><br>
<h2><a href = 'index.php?category=02'>People</a></h2><br>
<?}
}
?>
</html>