Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Everything posted by webguync

  1. I think this is an IE issue. I have a submit button for a form and when I use an image as the submit button it doesn't work in IE. Works fine in FF though. When I take out the image part and just use the default submit, works fine in IE. Here is the code with the image echo '<input name="Update" type="image" value="submit" id="Update" src="images/Update.png" />
  2. still getting the 3 results for every one record and an example result is... 53.466666666667 minutes AKA 00 seconds
  3. I know what is happening with this, just don't know why. The completion time is appearing every time below a persons info, for example in the first part of my script I am pulling the name, answers from the DB and displaying that. so what I am getting is... Tom Thumb Answer 1 Answer 2 Answer 3 etc. [time 1] [time 2] [time 3] Sally Smith Answer 1 Answer 2 Answer 3 etc. [time 1] [time 2] [time 3] Bob Jones Answer 1 Answer 2 Answer 3 [time 1] [time 2] [time 3] also a time that should be displaying as one minute is displaying as 20:56 hours (?)
  4. thanks for the tip. OK, I added the function as an include at the top of the page, but still getting some weirdness with the results. I have two records I am displaying and I am getting two results for Completion time, and they are EXACTLY the same for both records. Completion Time: 53 minutes Completion Time: 20:56 hours current code <html> <head> <title>Exam Results</title </head> <body> <?php include("includes/functions.php"); ?> <h1 class="results">exam results</h1> <table id="results"> <tr><th>Candidate Name</th></tr> <?php ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); $conn = mysql_connect("localhost","uname","pw"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("MyDB")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT Responses.name,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10,Answer11,Answer12 FROM Responses "; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<tr><td class='name'>{$row['name']}</td></tr>"; echo "<tr><td class='section'><strong>Section 1</strong></td></tr>"; for ($i =1;$i<9;++$i) { echo "<tr><td>{$row['Answer'.$i]}</td></tr>"; } echo "<tr><td class='section'><strong>Section 2</strong></td></tr>"; echo "<tr><td>{$row['Answer10']}</td></tr>"; echo "<tr><td class='section'><strong>Section 3</strong></td></tr>"; echo "<tr><td>{$row['Answer11']}</td></tr>"; echo "<tr><td class='section'><strong>Section 4</strong></td></tr>"; echo "<tr><td>{$row['Answer12']}</td></tr>"; $sql_timestamp = "SELECT TIMESTAMPDIFF(SECOND,submit_timestamp,login_timestamp) as cTime FROM Responses LEFT JOIN Candidates USING (user_id)"; $result_timestamp = mysql_query($sql_timestamp); if (!$result_timestamp) { echo "Could not successfully run query ($sql_timestamp) from DB: " . mysql_error(); exit; } while($row = mysql_fetch_assoc($result_timestamp)){ $formatted_completion_time = formatTime($row['cTime']); echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>\n"; echo $formatted_completion_time; echo "</td></tr>"; } } mysql_free_result($result); ?> </table> </body> </html> in the function include <?php function formatTime($cTime){ if($cTime < 60){ //less than 1 minute show seconds $formatted_completion_time = date("s",$cTime)." seconds"; }elseif($cTime < 3600){ //1 hour $formatted_completion_time = date("i",$cTime)." minutes"; }elseif($cTime < 86400){ //24 hours $formatted_completion_time = date("H:i",$cTime)." hours"; }else{ $formatted_completion_time = round($cTime/86400,0)." days"; } return $formatted_completion_time; } ?> the first records has timestamps of [2010-05-17 12:26:13,2010-05-17 11:32:45] and the second record [2010-05-25 18:44:52,2010-05-25 16:48:34]
  5. oh sorry, this is the PHP portion. <?php $conn = mysql_connect("localhost","username","pw"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("ETSI_Internal")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT Responses.editor_name,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10,Answer11,Answer12 FROM Responses "; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo "<tr><td class='name'>{$row['editor_name']}</td></tr>"; echo "<tr><td class='section'><strong>Section 1</strong></td></tr>"; for ($i =1;$i<9;++$i) { echo "<tr><td>{$row['Answer'.$i]}</td></tr>"; } echo "<tr><td class='section'><strong>Section 2</strong></td></tr>"; echo "<tr><td>{$row['Answer10']}</td></tr>"; echo "<tr><td class='section'><strong>Section 3</strong></td></tr>"; echo "<tr><td>{$row['Answer11']}</td></tr>"; echo "<tr><td class='section'><strong>Section 4</strong></td></tr>"; echo "<tr><td>{$row['Answer12']}</td></tr>"; function formatTime($cTime){ if($cTime < 60){ //less than 1 minute show seconds $formatted_completion_time = date("s",$cTime)." seconds"; }elseif($cTime < 3600){ //1 hour $formatted_completion_time = date("i",$cTime)." minutes"; }elseif($cTime < 86400){ //24 hours $formatted_completion_time = date("H:i",$cTime)." hours"; }else{ $formatted_completion_time = round($cTime/86400,0)." days"; } return $formatted_completion_time; } $sql_timestamp = "SELECT TIMESTAMPDIFF(SECOND,submit_timestamp,login_timestamp) as cTime FROM Responses LEFT JOIN Candidates USING (user_id)"; $result_timestamp = mysql_query($sql_timestamp); if (!$result_timestamp) { echo "Could not successfully run query ($sql_timestamp) from DB: " . mysql_error(); exit; } while($row = mysql_fetch_assoc($result_timestamp)){ $formatted_completion_time = formatTime($row['cTime']); echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>\n"; echo $formatted_completion_time; echo "</td></tr>"; } } mysql_free_result($result); ?>
  6. function formatTime($cTime){ if($cTime < 60){ //less than 1 minute show seconds $formatted_completion_time = date("s",$cTime)." seconds"; }elseif($cTime < 3600){ //1 hour $formatted_completion_time = date("i",$cTime)." minutes"; }elseif($cTime < 86400){ //24 hours $formatted_completion_time = date("H:i",$cTime)." hours"; }else{ $formatted_completion_time = round($cTime/86400,0)." days"; } return $formatted_completion_time; } $sql_timestamp = "SELECT TIMESTAMPDIFF(SECOND,submit_timestamp,login_timestamp) as cTime FROM Responses LEFT JOIN Editor_Candidates USING (user_id)"; $result_timestamp = mysql_query($sql_timestamp); if (!$result_timestamp) { echo "Could not successfully run query ($sql_timestamp) from DB: " . mysql_error(); exit; } while($row = mysql_fetch_assoc($result_timestamp)){ $formatted_completion_time = formatTime($row['cTime']); echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>\n"; echo $formatted_completion_time; echo "</td></tr>"; }
  7. now I get this error. "Fatal error: Cannot redeclare formattime() (previously declared in /path_to_file/Results.php on line 66"
  8. thanks again for the help. I think I am getting close, but using the expanded code you provided I get the following error. " Fatal error: Call to undefined function formatTime() in /path_to_file/Results.php on line 74"
  9. as an amendment I noticed when I take unix_timestamp out of the SQL and run it through PHPMyAdmin I get non zero values. cTime -00:53:28 -01:56:18 but in the PHP I get the following warning. Notice: A non well formed numeric value encountered in /path_to_file/Results.php on line 77
  10. thanks, I think the code will work ok, but my SQL produced cTime 0 0 which of course produces zero in my output. No errors or anything. Any ideas on why the zeros are being produced?
  11. I have this code so far, but the SQL isn't working b/c nothing is being selected. $sql_timestamp = "SELECT unix_timestamp(TIMEDIFF(submit_timestamp, login_timestamp)) as cTime FROM Responses LEFT JOIN Candidates USING (user_id)"; $result_timestamp = mysql_query($sql_timestamp); if (!$result_timestamp) { echo "Could not successfully run query ($sql_timestamp) from DB: " . mysql_error(); exit; } //some conditions if needed ie if($row['cTime'] < 60){ //less than 1 minute show seconds $formatted_completion_time = date("s",$row['cTime'])." seconds"; }elseif($row['cTime'] < (3600)){ $formatted_completion_time = date("i",floor($row['cTime']))." minutes"; }else{ $formatted_completion_time = date("H",floor($row['cTime']))." hours"; //technically wrong as it won't show more than 23 hours but you get the idea } echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>"; echo $formatted_completion_time; echo " minutes"; echo "</td></tr>"; also getting undefined index notices for cTime. This may also be doe to the fact that the SQL produces no results.
  12. @medtechie that might work for what I need. I think part of my problem is the login_timestamp and submit_timestamp are in two different tables (Candidates and Responses respectively), and the user_id's weren't the same so the calculations are off. Can I use this as the SQL? $SQL = "SELECT unix_timestamp(TIMEDIFF(submit_timestamp, login_timestamp)) as cTime FROM Responses LEFT JOIN Candidates USING (user_id)"; also how would I echo out the results with this method? thanks for all the help so far.
  13. ok, I see I just had the fields reversed, which is why I am getting the negative value. In the PHP I provided though, I get a result of 21248056 minutes not sure why this is being output if the result is 2 minutes and 28 seconds.
  14. I almost have this correct, but the output isn't what is should be for subtracting the difference between two timestamp fields. Here is my code $login_time = strtotime($row['login_timestamp']); $submit_time = strtotime($row['submit_timestamp']); $completion_time = $login_time - $submit_time; $completion_time /= 60; $formatted_completion_time = floor($completion_time ); echo "<tr><th class='complete'>Completion Time:</th></tr><tr><td>"; echo $formatted_completion_time; echo " minutes"; echo "</td></tr>"; -21248057 minutes is the output when it should be something like 3 minutes. When I run SQL to determine the difference I get -00:02:28 which I don't understand either. The SQL to get that is SELECT TIMEDIFF('2010-05-26 10:13:53', '2010-05-26 10:16:21');
  15. ok thanks. No error now. The only problem I have now is the result is something like. 21235172.75 not sure what this is in? I want a result such as 60 minutes. The database info is. login_timestamp=>2010-05-17 11:32:45, submit_timestamp=>2010-05-17 12:26:13
  16. still getting an error unfortunately. echo "<tr><th>Completion Time:</th></tr><tr><td>" . date('F j, Y g:i:sa'), strtotime($row['submit_timestamp']) - strtotime($row['login_timestamp']))/60 . "</td></tr>";
  17. I am getting an error w/ this code. Don't think my syntax is quite right. Was hoping for some assistance. echo "<tr><th>Completion Time:</th></tr><tr><td>" . date('F j, Y g:i:sa'), (strtotime(['submit_timestamp']) - strtotime($row['login_timestamp']))/60 . "</td></tr>";
  18. sorry, but to further clarify. I have two timestamps in two different MySQL tables(Responses,Candidates). I am using SQL to SELECT the two timestamps here. $sql = "SELECT submit_timestamp,login_timestamp FROM Responses LEFT JOIN Candidates USING (user_id)"; trying to determine the difference b/t the time from login to submit in minutes.(this is a form). I have done a lot of google-ing, but haven't come up with any solutions yet. any ideas?
  19. Just using the info in the database fields can I take this row of data. <td>" . date('F j, Y g:i:sa', strtotime($row["login_timestamp"] )) . "</td> and subtract from another timestamp (submit_timestamp)?...if so what is the proper syntax for that? I tried this, but not working. echo "<tr><th>Completion Time:</th></tr><tr><td>" . date('F j, Y g:i:sa', strtotime($row["login_timestamp"] - ["submit_timestamp")) . "</td></tr>";
  20. thanks. Where would the date() and strtotime() functions need to go in the code I provided? Need a little help with the syntax.
  21. Hi, I have a timestamp in MySQL pulling the data out like so... echo "<td>{$row["submit_timestamp"]}</td></tr>"; understand I can use strtotime to get a more readable date and time. Currently looks like 2010-05-17 11:32:45 would rather it say, May 17, 2010 11:32:45am and if it is pm be 9:30:45pm in that format. thanks in advance for any assistance.
  22. Since the variable is coming from a Session, I tried $_SESSION['name'] = $_POST['name']; but this didn't work either. Any other ideas?
×
×
  • 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.