Jump to content

dlmagers

Members
  • Posts

    6
  • Joined

  • Last visited

dlmagers's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am trying to display scores by what the user is requesting either 'Average', 'Total', or 'Both'. The following is my code for the loop_tester.php and below that is the code for my index.php. I am trying to add a switch statement to the index.php file that will sets values for only the average calculation if the user selected the "average" radio button, only the total calculation if the user selected the "total" radio button, both the average and total if the user selected the "both" button. After the user puts in the scores and then selects either 'average', 'total', 'both' it should display what the user selected. So I am still learning how to do this but I need help starting out....would someone please look at what I have thus far and direct me into a direction of where I need to go? PLEASE HELP! NOTE: The output should look like this..... http://wcet2.waketech.edu/wrconway/web182/lesson7/ch08_ex2/ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Loop Tester</title> <link rel="stylesheet" type="text/css" href="main.css"/> </head> <body> <div id="content"> <h1>Loop Tester</h1> <h2>Process Scores</h2> <form action="." method="post"> <p> <input type="hidden" name="action" value="process_scores" /> <br /> <label>Score 1:</label> <input type="text" name="scores[]" value="<?php echo $scores[0]; ?>"/><br /> <label>Score 2:</label> <input type="text" name="scores[]" value="<?php echo $scores[1]; ?>"/><br /> <label>Score 3:</label> <input type="text" name="scores[]" value="<?php echo $scores[2]; ?>"/><br /> <label> </label> <input type="submit" value="Process Scores" /><br /> </p> <p>What would you like to do?</p> <p> <label>Average</label> <input name="Average" type="radio" value="Average" checked="checked" /> <br /> <label>Total</label> <input name="Average" type="radio" value="Average" /> <br /> <label>Both</label> <input name="Average" type="radio" value="Average" /> </p> <p> </p> <p> <input type="submit" name="Calculate" id="Calculate" value="Calculate" /> </p> <p><br /> <label>Scores:</label> <span><?php echo $scores_string; ?></span><br /> <label>Score Total:</label> <span><?php echo $score_total; ?></span><br /> <label>Average Score:</label> <span><?php echo $score_average; ?></span><br /> </p> </form> <br /> <h2>Process 1000 Die Rolls</h2> <form action="." method="post"> <input type="hidden" name="action" value="process_rolls" /> <label>Number to Roll:</label> <select name="number_to_roll"> <!-- TODO: Use a for loop to display these options ! --> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select><br /> <label> </label> <input type="submit" value="Process Rolls" /><br /> <label>Maximum Rolls:</label> <span><?php echo $max_rolls; ?></span><br /> <label>Average Rolls:</label> <span><?php echo $average_rolls; ?></span><br /> </form> </div> </body> </html> And this is what I have got for my index.html <?php if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = 'start_app'; } switch ($action) { case 'start_app': $scores = array(); $scores[0] = 70; $scores[1] = 80; $scores[2] = 90; break; case 'process_scores': $scores = $_POST['scores']; // validate the scores // TODO: Convert this if statement to a for loop if (empty($scores[0]) || empty($scores[1]) || empty($scores[2]) || !is_numeric($scores[0]) || !is_numeric($scores[1]) || !is_numeric($scores[2])) { $scores_string = 'You must enter three valid numbers for scores.'; break; } // process the scores // TODO: Add code that calculates the score total $scores_string = ''; foreach ($scores as $s) { $scores_string .= $s . '|'; } $scores_string = substr($scores_string, 0, strlen($scores_string)-1); // calculate the average $score_average = $score_total / count($scores); // format the total and average $score_total = number_format($score_total, 2); $score_average = number_format($score_average, 2); break; case 'process_rolls': $number_to_roll = $_POST['number_to_roll']; $total = 0; $count = 0; $max_rolls = -INF; // TODO: convert this while loop to a for loop while ($count < 1000) { $rolls = 1; while (mt_rand(1, 6) != 6) { $rolls++; } $total += $rolls; $count++; $max_rolls = max($rolls, $max_rolls); } $average_rolls = $total / $count; break; } include 'loop_tester.php'; ?>
  2. David, Ok first of all thank you. I tried the code and I did a couple tweeking and it is giving me a message in the browser the I have connect to mysql but then on the next line it is telling me that the Query could not be established because no database was selected. Not sure what I did. My URL is here. http://wcet2.waketech.edu/dlmagers/WEB187/PhoneDirectoryPageFiles%281%29/index.php
  3. Denno, I used your advice and when I bring it up in the browser I am not seeing what I need to see. I am not even seeing any HTML <p> or <h2>. I think I am doing something else wrong. This is what I changed it to. <?php $dbhost = 'localhost'; $dbuser = 'w187_dxxxxxxx'; $dbpass = 'Dxxxxxxx'; // Connect to database server $conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die (mysql_error ()); echo "You are now connected to MySQL<br /><br />"; // Select database $dbname = 'employee_directory'; mysql_select_db($dbname); // Get data from the database depending on the value of the id in the URL $query = "SELECT * FROM employee_directory ORDER BY lastname"; $result = mysql_query($query) or die(mysql_error()); ?> <table width="50%"> <tr> <th width="3%">ID</th> <th width="48%">Last Name</th> <th width="25%">Cell</th> <th width="24%">Email</th> </tr> <tr> <?php while($row = mysql_fetch_array($result)){ //Opening curly brace echo "<td>".$row['id']."</td>"; echo "<td>".$row['lastname']."</td>"; echo "<td>".$row['cellphone']."</td>"; echo "<td>".$row['email']."</td>";} //closing curly brace?> </tr> </table> Can you see anything else that might throw it off? Thank you in advance. I appreciate your opinion.
  4. Denno, Ok, should I put curly brackets after the while statement? And Gurus, so maybe I should use the ip address in from of the phpmyadmin? I think I need to fix the error that Denno saw in my code first. This is the error I am getting now. "; // Select database $dbname = 'employee_directory'; mysql_select_db($dbname); // Get data from the database depending on the value of the id in the URL $query = "SELECT * FROM employee_directory ORDER BY lastname"; $result = mysql_query($query) or die(mysql_error()); ?> { }
  5. I didn't want to have to post this question. I need someones professional help with connecting to my school phpmysql server. I have my code here.</p> If someone sees that there might be something wrong please please help me and at least point me in the right direction.<br /> What I need to do is extract data from a table that I have created employee_directory that I need to display in a table on a responsive site. <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Phone Directory</title> <!--Mobile specific meta goodness --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--google fonts--> <link href='http://fonts.googleapis.com/css? family=PT+Sans:400,700|PT+Serif:400,700,400italic' rel='stylesheet' type='text/css'> <!--css--> <link rel="stylesheet" type="text/css" href="main.css" /> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!--[if !IE]><!--> <style> /* This query will take effect for any screen smaller than 760px and also iPads specifically. */ @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) { /* Force table to not be like tables anymore */ #employeedb { border:1px solid #000; border-collapse:collapse; font-family:Vollkorn; font-size:12px; text-align:right; } #employeedb th { border: 1px solid #333; padding: 3px 6px; color: #e9edd5; } #employeedb td { border:1px solid #999; padding:3px 6px; } table, thead, tbody, th, td, tr { display: block; color: #c6f104; font-family: Vollkorn; margin-right: auto; margin-left: auto; padding-left: 5px; } /* Hide table headers (but not display: none;, for accessibility) */ thead tr { position: absolute; top: -9999px; left: -9999px; } tr { border: 1px solid #ccc; } td { /* Behave like a "row" */ border: none; border-bottom: 1px solid #eee; position: relative; padding-left: 50%; } td:before { /* Now like a table header */ position: absolute; /* Top/left values mimic padding */ top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; } /* Label the data */ td:nth-of-type(1):before { content: "ID"; } td:nth-of-type(2):before { content: "Last Name"; } td:nth-of-type(3):before { content: "Cell Number"; } td:nth-of-type(4):before { content: "Email"; } } /* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 320px) and (max-device-width : 480px) { body { padding: 0; margin: 0; width: 320px; } } /* iPads (portrait and landscape) ----------- */ @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) { body { width: 495px; } } .wrapper .background-illusion h2 { color: #d4f24e; font-family: Vollkorn; font-size: 29px; } body table tr th h3 { color: #c6f104; } body div table tr th { color: #B0F104; } </style> </head> <body> <div class="wrapper"> <header class="background-illusion"> <h2 align="center">Phone Directory</h2> <p align="center">for Student Admin Department at WTCC<br> WEB 000 | Assignment 7<br> </p> </header> </div> <nav class="nav right"> <ul> <li class="current"><a href="index.php">Home</a></li> <li><a href="#">Assignments</a></li> <li><a href="#">Discussion Board</a></li> <li><a href="#">Support</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <table width="85%"> <tr> <th>ID</th> <th>Last Name</th> <th>Cell</th> <th>Email</th> </tr> <tr> <?php $dbhost = '198.86.244.3/phpmyadmin/'; $dbuser = 'XXXX_dbXXXXXX'; $dbpass = 'DxXxXxX'; // Connect to database server $conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die (mysql_error ()); echo "You are now connected to MySQL<br /><br />"; // Select database $dbname = 'employee_directory'; mysql_select_db($dbname); // Get data from the database depending on the value of the id in the URL $query = "SELECT * FROM employee_directory ORDER BY lastname"; $result = mysql_query($query) or die(mysql_error()); ?> <?php while($row = mysql_fetch_array($result)); ?> <td><?php echo $row['id']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['cellphone']; ?></td> <td><?php echo $row['email']; ?></td> </tr> </table> <footer class="background-illusion"> <div class="container"> <div align="center"> <p>Copyright © 2013 | <a href="http://dianamagers.com">XXXXXXX</a> | Spring Semester 2013 </p></div> </div> </footer> </div> </body> </html> Of course, I couldn't provide my username and password ..... Sorry. I don't need to know that. This is what it looks like on the server now. http://wcet2.waketec...es(1)/index.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.