Jump to content

karatekid36

Members
  • Posts

    148
  • Joined

  • Last visited

    Never

Everything posted by karatekid36

  1. Why is it reloading and not entering the data like it should? <?php session_name ('YourVisitID'); session_start(); // Start the session. // If no session value is present, redirect the user. if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } $url .= '../index.php'; // Add the page. header("Location: $url"); exit(); // Quit the script. } // Check for a valid user ID, through GET or POST. if ( (isset($_GET['event_id'])) && (is_numeric($_GET['event_id'])) ) { // Accessed through view_users.php $event_id = $_GET['event_id']; } elseif ( (isset($_POST['event_id'])) && (is_numeric($_POST['event_id'])) ) { // Form has been submitted. $event_id = $_POST['event_id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; exit(); } $page_title = 'Attendance of Psi Beta'; require_once ('../includes/mysql_connect.php'); // Connect to the db. // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. foreach($_POST as $value){ if ( empty($value) ){ $msg = 'Please fill out all required fields.'; return $msg; } } if (empty($errors)) { // If everything's OK. // Register the user in the database. // Check for attendance. $query5 = "SELECT eid FROM attendance WHERE eid='$event_id'"; $result5 = mysql_query($query5); if (mysql_num_rows($result5) == 1) { // Make the query. foreach($attend as $key => $value2){ mysql_query("UPDATE attendance SET attend_status='$value2' WHERE mid=$user_id AND eid=$event_id") or die(mysql_error()); } $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK. // Send an email, if desired. // Redirect the user to the view_users.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/attendance.php'; header("Location: $url"); exit(); } else { // If it did not run OK. $errors[] = 'Attendnace for this meeting could not be entered.'; // Public message. $errors[] = mysql_error() . '<br /><br />Query: ' . $query5; // Debugging message. } } else { // Email address is already taken. $errors[] = 'Attendance has already been taken for this event.'; } } // End of if (empty($errors)) IF. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional. // Page header. echo '<h1 id="mainhead">Attendance</h1>'; $query4 ="SELECT * FROM events WHERE event_id=\"$event_id\""; $result4 = @mysql_query ($query4); // Run the query. $row4 = mysql_fetch_array ($result4); ?> <form action="event_attendance_admin.php?event_id=<?php echo''.$row4['event_id'] .'' ; ?>" method="post"> <? // Make the query. $query3 = "SELECT brothers.user_id, CONCAT(brothers.last_name, \", \", brothers.first_name) AS BrotherName, brothers.status, attendance.attend_status FROM brothers JOIN events RIGHT JOIN attendance ON (events.event_id = attendance.eid AND brothers.user_id = attendance.mid ) WHERE events.event_id = \"$event_id\" AND brothers.status = 'Undergraduate' GROUP BY brothers.user_id ORDER BY brothers.last_name"; $result3 = mysql_query ($query3); // Run the query. // Table header. echo '<h1 align="center">' . $row4['name'] .', ' . $row4['date'] .'</h1> <table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Current Attendance</b></td> <td align="left"><b>Update Attendance</b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_array($result3, MYSQL_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['BrotherName'] . '</td> <td align="left">' . $row['attend_status'] . '</td>'; if ($row['attend_status'] == Present ) { echo '<td align="left">Present<input type ="radio" name="attend['.$row['user_id'].']" value="Present" checked="checked" />'; } else { echo '<td align="left">Present<input type ="radio" name="attend['.$row['user_id'].']" value="Present" />'; } if ($row['attend_status'] == Excused ) { echo 'Excused<input type ="radio" name="attend['.$row['user_id'].']" value="Excused" checked="checked" />'; } else { echo 'Excused<input type ="radio" name="attend['.$row['user_id'].']" value="Excused" />'; } if ($row['attend_status'] == Unexcused ) { echo 'Unexcused<input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" checked="checked" />'; } else { echo 'Unexcused<input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" />'; } echo '</tr>'; } echo '</table><p><input type="submit" name="submit" value="Update Attendance" /></p> <input type="hidden" name="submitted" value="TRUE" /></form>'; ?>
  2. This is exactly what I am looking for. I would be very interested in seeing how you get the events in the code.
  3. I would def like to see the finished product because your solution sounds like it could work for my needs.
  4. howdy everyone, So I am trying to generate an event calendar for my organization as our calendar. I have built calendars in the past, but I am having a hard time taking those applications and marrying them into my new need. My prior calendars where strictly dates. I could construct this by hand, setting variables for each day and month, but with the power of PHP there has to be a better way. Obviously I need to generate dynamically a calendar, but with in the day, be it in the <td> tags or however it is constructed, I would like it to fill it with events that I have in table. The dates are stored as yyyy-mm-dd in the table so they should be easy enough, but I really just do not have a solid idea of how I can get it to echo the event's title and location in each day where the date on the cal matches the date on the event. Also, shifting to prior and next months would be killer too. If anyone has any ideas as to where I should start on this, please let me know. Thanks and have a great day.
  5. Thank you very much. I know understand how this works. I got it to worl exactly the way I needed it to.
  6. When pulling the a paragraph from a table, what would be the best way to set it up? Do you create a variable that is equal to what is being pulled from the table or do you just use it when echo-ing the data?
  7. Below is an image of a forum that I read and I like how they have some of the message displayed, but then they cut it off with a more button at the end. I was curious if anyone might know how to do this? Thank you in advance for any help.
  8. Hey Everyone, What is the best way to store zip codes in a db? I can not get the zip code to display properly if it starts with a 0 meaning the 0xxxx wont display, only the xxxx. Thank you for the help.
  9. thank you very much. I now understand how this works.
  10. Howdy everyone, I am pulling the last name from a table and I want the name to display as First L. not First Last. I am not sure how to do this in a function. All I need is the first letter of the last name followed by a period. Can anyone explain this to me? Thank you. karatekid36
  11. Right now I am receiving this error from your code which I am trying to debug... Parse error: syntax error, unexpected $end in /home/carrigan/public_html/php_attend/event_attendance_admin.php on line 113 Let me know what you think.
  12. All I was saying is that when I have tried to generate this code on my own, I have run into issues with quotes and such. Is there anyone who could point me in the right direction as to how to create the IF/ELSE statement?
  13. Howdy Everyone, I have the following code where I want to create an update query in a form so that I can update my groups attendance. The variables 100% are working and are pulling the correct info. In the update attendance column, I would like an If else statement that says if the attend_status == present echo SELECTED VALUE="", so that the pull down menu will display the current attendance value. From there I will select the new update attendance info and then submit it using an update query. Below is the code. I am running into other problems with the quotation marks in such because this is all located within the <php> tags. Thanks for the help and let me know if I am being unclear at all. THANKS! <code>// Table header. echo '<h1 align="center">' . $row2['name'] .', ' . $row2['date'] .'</h1> <table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Current Attendance</b></td> <td align="left"><b>Update Attendance</b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['BrotherName'] . '</td> <td align="left">' . $row['attend_status'] . '</td> <td><select><option>Present</option><option>Excused</option><option>Unexcused</option></select></td> </tr> '; }</code>
  14. I have used this method before and it has worked fine. I am just unsure why I can not get it to work now...
  15. Hey Everyone. How you doing? I have an attendance page which I would like to take attendance over a certain time period. The dates will come from the url which will be something like this... attendance.php?start=2007-01-01&end=2007-06-31. In my code that follows this, I have tried to insert these variables into the code, but I can not really seem to get this to work. The dates in my table are yyyy-mm-dd format. I need some help in trying to figure how to make this work. The start and end variables will come from another page where the user specifies the start an end date. That is easy enough, I just am having trouble getting this bad boy working. I would like the sql statement to pick up the information over the time period specified. Thank you in advance for your help. Any help would be greatly appreciated. <?php session_name ('YourVisitID'); session_start(); // Start the session. // If no session value is present, redirect the user. if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } $url .= '/index.php'; // Add the page. header("Location: $url"); exit(); // Quit the script. } $page_title = 'Attendance of Psi Beta'; require_once ('includes/mysql_connect.php'); // Connect to the db. $query2 = mysql_query("SELECT * FROM brothers WHERE user_id='$user_id'"); $row2 = mysql_fetch_assoc($query2); if ($row2['admin'] == 'admin'){ include ('./includes/header_admin.html'); } else { include ('./includes/header.html'); } // Check for a valid user ID, through GET or POST. if ( (isset($_GET['start'])) && (is_numeric($_GET['start'])) ) { // Accessed through view_users.php $start = $_GET['start']; } elseif ( (isset($_POST['start'])) && (is_numeric($_POST['start'])) ) { // Form has been submitted. $start = $_POST['start']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('./includes/footer.html'); exit(); } // Check for a valid user ID, through GET or POST. if ( (isset($_GET['end'])) && (is_numeric($_GET['end'])) ) { // Accessed through view_users.php $end = $_GET['end']; } elseif ( (isset($_POST['end'])) && (is_numeric($_POST['end'])) ) { // Form has been submitted. $end = $_POST['end']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('./includes/footer.html'); exit(); } // Page header. echo '<h1 id="mainhead">Attendance</h1>'; // Make the query. $query = "SELECT brothers.user_id, CONCAT(brothers.last_name, \", \", brothers.first_name) AS BrotherName, brothers.status, 100 * (SUM(attendance.attend_status IN ('Present','Late','Excused') AND type = 'Mandatory')) / (SELECT COUNT(*) FROM events WHERE type = 'Mandatory' AND date BETWEEN \"$start\" AND \"$end\") AS Attendance FROM brothers JOIN events LEFT JOIN attendance ON (events.event_id = attendance.eid AND brothers.user_id = attendance.mid ) WHERE events.type = 'Mandatory' AND events.date BETWEEN \"$start\" AND \"$end\" AND brothers.status = 'Undergraduate' GROUP BY brothers.user_id ORDER BY brothers.last_name"; $result = mysql_query ($query); // Run the query. if (!$result) { echo "The Query: $query Produced the error: ".mysql_error(); exit; } // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Attendance</b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['BrotherName'] . '</td> <td align="right">' . $row['Attendance'] . '</td> </tr> '; } echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection. include ('includes/footer.html'); // Include the HTML footer. ?>
  16. In this query: SELECT * FROM prof_ratings WHERE prof_id=$prof_id ORDER BY date_entered DESC; One of the row items pulled is user_id. I have a user table which has a primary key of user_id. In this new query, I would like to have the user name pulled and put into my web page instead of simply displaying the user_id. In the user table, the name is broken into first_name and last_name. How can I pull the user's name with this query so that I can place it in my web page? Thanks
  17. Hey Everyone! In this code, almost everything is working perfectly, but for my second query, I have six records that I want displayed in their own table like I have. I know that a loop would probably work, but I am just really not sure how to go about this. I would like the code to display a table of each of the records. Any assistance would be great! // Retrieve the user's information. $query = "SELECT *, (SELECT COUNT(rating) FROM prof_ratings WHERE prof_id=$prof_id) AS total, ((SELECT SUM(rating) FROM prof_ratings WHERE prof_id=$prof_id) / (SELECT COUNT(rating) FROM prof_ratings WHERE prof_id=$prof_id)) AS rating FROM professors WHERE prof_id=$prof_id"; $result = @mysql_query ($query); // Run the query. // Get the user's information. $row = mysql_fetch_array ($result); // Create the form. echo '<br /><br /><br /><br /> <table width="250" height="50" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td colspan="3" align="center"><b>' . $row[2] .', ' . $row[1] .'</b></td> </tr> <tr> <td width="195" scope="row">Total Ratings: </td> <td width="112" colspan="2">' . $row['total'] .'</td> </tr> <tr> <td scope="row">Average Rating: </td> <td colspan="2">' . $row['rating'] .'</td> </tr> </table>'; $query2 = "SELECT * FROM prof_ratings"; $result2 = @mysql_query ($query2); // Run the query. // Get the user's information. $row = mysql_fetch_array ($result2); echo'<br /><br /> <table width="400" border="2" cellspacing="0" cellpadding="5" align="center"> <tr> <td width="74">Brother:</td> <td width="174">' . $row[2] .'</td> <td width="174">Class:</td> <td width="174">' . $row[5] .'</td> </tr> <tr> <td>Rating:</td> <td>' . $row[1] .'</td> <td>Date:</td> <td>' . $row[4] .'</td> </tr> <tr> <td>Comment:</td> <td colspan="3">' . $row[6] .'</td> </tr> </table>';
  18. I would like to get all from the professors table and a count of the ratings from the prof_rating table and I need both where the prof_id equals the prof_id variable which comes from the url. "SELECT *, (SELECT COUNT(rating) FROM prof_ratings WHERE prof_id=$prof_id) AS total FROM professors WHERE prof_id=$prof_id"; This is not the right sql statement, or at least I am not sure because it is displaying nothing in the following code: $query = "SELECT *, (SELECT COUNT(rating) FROM prof_ratings WHERE prof_id=$prof_id) AS total FROM professors WHERE prof_id=$prof_id"; $result = @mysql_query ($query); // Run the query. // Get the user's information. $row = mysql_fetch_array ($result, MYSQL_NUM); // Create the form. echo '<br /><br /><br /><br /> <table width="250" height="100" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td colspan="3" align="center"><b>' . $row[2] .', ' . $row[1] .'</b></td> </tr> <tr> <td width="195" scope="row">Total Ratings: </td> <td width="112" colspan="2">' . $row['total'] .'</td> </tr> <tr> <td scope="row">Average Rating: </td> <td colspan="2"> </td> </tr> </table>';
  19. I have some birthdates in a table in the YYYY-MM-DD format and I was curious what the best way is to calculate a person's age so that it could in turn be displayed in a web page?
  20. I need help thinking this out. Since switching to a non binary attendance system, I have to had to make some adjustments to code, and right now I have seen this code about a million times. My problem now lies in the calculation of Attendance. Right now there is three options for a members attendance. There is Present, Excused, and Unexcused. If there were only two meetings in the time period we were concerned about and member x was present for meeting one and excused for meeting two, this member would have a 100% attendance record. If another member were present for meeting one and Unexcused for meeting two, they have a 50% attendance record. Okay, with that being said, I need a little help with the sql statement that will make this a reality. As some added complication, this attendance stuff only matters for events/meeting that have a mandatory "status". My code is posted below, but I am running into some road blocks because if there is only one event during the time period and the person was excused for the one meeting, the math produces the answer of infinity and then will post nothing in the proper column, but in reality their attendance record is 100% because they were excused for only meeting of the time period, which does not count against them. Also, the attendance measurement in general is not calculating properly when excused and unexcused get tossed into the mix. I just need a little help thinking this out and ANY assistance would be greatly appreciated. If you need more clarification feel free to ask. "SELECT brothers.user_id, CONCAT(brothers.last_name, \", \", brothers.first_name ) AS BrotherName, brothers.status, 100 * (SUM(attendance.attend_status IS NOT NULL AND attendance.attend_status IN ('Present','Late','Unexcused') AND TYPE = 'Mandatory')) / ((SELECT COUNT(*) FROM events WHERE TYPE = 'Mandatory' AND date BETWEEN '2007-06-11' AND '2007-06-12') - SUM(attendance.attend_status = 'Excused')) AS Attendance FROM brothers JOIN events LEFT JOIN attendance ON (events.event_id = attendance.eid AND brothers.user_id = attendance.mid ) WHERE events.type = \"Mandatory\" AND events.date BETWEEN \"2007-06-11\" AND \"2007-06-12\" AND brothers.status = \"Undergraduate\" GROUP BY brothers.user_id ORDER BY brothers.last_name";
  21. Why are these two line producing an error. All of the variables are fine it is the actual structure of this code. foreach($attend as $key => $value2){ mysql_query("INSERT INTO attendance ('eid', 'mid','attend_status') VALUES ('$eventid','$key','$value2') or die(mysql_error()"); }
×
×
  • 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.