forked from jaiswalaman/Online-Notes-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadnotes.php
46 lines (40 loc) · 1.48 KB
/
loadnotes.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
<?php
session_start();
include('connection.php');
//get the user_id
$user_id = $_SESSION['user_id'];
//run a query to delete empty notes
$sql = "DELETE FROM notes WHERE note=''";
$result = mysqli_query($link, $sql);
if(!$result){
echo '<div class="alert alert-warning">An error occured!</div>'; exit;
}
//run a query to look for notes corresponding to user_id
$sql = "SELECT * FROM notes WHERE user_id ='$user_id' ORDER BY time DESC";
//shows notes or alert message
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
$note_id = $row['id'];
$note = $row['note'];
$time = $row['time'];
$time = date("F d, Y h:i:s A", $time);
echo "
<div class='note'>
<div class='col-xs-5 col-sm-3 delete'>
<button class='btn-lg btn-danger' style='width:100%'>delete</button>
</div>
<div class='noteheader' id='$note_id'>
<div class='text'>$note</div>
<div class='timetext'>$time</div>
</div>
</div>";
}
}else{
echo '<div class="alert alert-warning">You have not created any notes yet!</div>'; exit;
}
}else{
echo '<div class="alert alert-warning">An error occured!</div>'; exit;
// echo "ERROR: Unable to excecute: $sql." . mysqli_error($link);
}
?>