karatekid36 Posted July 30, 2007 Share Posted July 30, 2007 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/62409-php-url-variable-help/ Share on other sites More sharing options...
Crow Posted July 31, 2007 Share Posted July 31, 2007 Use $_GET['start'] and $_GET['end'] to get those values. When submitting them into the database use {$_GET['start']} and {$_GET['end']} so they evaluate before the SQL. Hope this helps, Steve Quote Link to comment https://forums.phpfreaks.com/topic/62409-php-url-variable-help/#findComment-312215 Share on other sites More sharing options...
karatekid36 Posted August 1, 2007 Author Share Posted August 1, 2007 I have used this method before and it has worked fine. I am just unsure why I can not get it to work now... Quote Link to comment https://forums.phpfreaks.com/topic/62409-php-url-variable-help/#findComment-313036 Share on other sites More sharing options...
karatekid36 Posted August 3, 2007 Author Share Posted August 3, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/62409-php-url-variable-help/#findComment-314900 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.