Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <!-- Plotly.js -->
- <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
- </head>
- <body>
- <p>
- <?php
- if(!isset($_COOKIE["usr"])) {
- header("Location: WellbrosLoginTitle.html",true);
- } else {
- $user_id = $_COOKIE["usr"];
- }
- try {
- // Process form
- $ini_array = parse_ini_file("data.ini.php");
- $host = $ini_array['host'];
- $dbname = $ini_array['dbname'];
- $user = $ini_array['user'];
- $password = $ini_array['password'];
- //print_r($ini_array);
- $user_id = $_COOKIE["usr"];
- $dbh = new PDO("mysql:dbname=$dbname;host=$host", $user, $password);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $dbh->prepare("SELECT * FROM pams_survey_attempts INNER JOIN PAMS_surveys ON PAMS_surveys.survey_id = PAMS_survey_attempts.survey_id WHERE user_id = $user_id");
- $stmt->execute();
- $rows = $stmt->fetchAll();
- //print_r($rows[0]);
- //echo(count($rows));
- $time_array = array_fill(0, count($rows), "initialization string");
- $mood_rating = array_fill(0, count($rows), -999);
- for($i = 0; $i < count($rows); $i++) {
- $row_array = $rows[$i];
- $time_val = $row_array["date_added"] . " " . $row_array["time_added"];
- $time_array[$i] = $time_val;
- $mood_val = $row_array["mood"];
- $mood_rating[$i] = $mood_val;
- }
- //print_r($time_array);
- //print_r($mood_rating);
- $mood_data = [ [
- "x" => $time_array,
- "y" => $mood_rating,
- "type" => "scatter"
- ] ];
- //foreach ($rows as $row) {
- //echo $row['survey_id'] . '<br />';
- //}
- //$users = $getUsers->fetchAll();
- //foreach ($users as $user) {
- // echo $user['username'] . '<br />';
- //}
- //foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
- //echo $v;
- //}
- //if ($stmt->execute(array($_POST['age_number']))) {
- //while ($row = $stmt->fetch()) {
- //echo "<pre>";
- //print_r($row);
- //}
- //}
- //$smt = foreach($pdo->query("select * from pravin_table");
- //print_r($smt);
- //foreach( $pdo->query("select * from pravin_table") as $k) {
- //echo "<pre>";
- //print_r($k);
- //}
- }
- catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- ?>
- </p>
- <div id="mood_graph"></div>
- <script>
- var sample_data = [
- {
- x: ['2013-10-04 22:23:00', '2013-12-04 22:23:00'],
- y: [1, 3],
- type: 'scatter'
- }
- ];
- var layout = {
- title: 'Mood Rating Over Time',
- xaxis: {
- title: 'Time Point',
- showgrid: false,
- zeroline: false
- },
- yaxis: {
- title: 'Mood (Rating from 1-10)',
- showline: false
- }
- };
- Plotly.newPlot('mood_graph', <?php echo json_encode($mood_data) ?>, layout);
- </script>
- <br>
- <center>Ideally we'd be graphing a lot more data than just the Mood over Time. We also plan to display written entries and show corellations between various data points like sleep and mood, or exercise and stress.
- <form action="wellBroSurvey.php"><input type="submit" value="Take Survey"></form>
- </center>
- </body>
- </html>
Add Comment
Please, Sign In to add comment