Jump to content

I'm stuck!


dweir

Recommended Posts

Hello all, I'm new to the forum and also PHP programming.

Here's my dilema, I have a scheduling form that will allow students to select dates and shifts for their clinical rotations.  I have a calendar with each day filled with available clinical shifts.  Currently the form allows for the student to select one clinical date, shift, clinical center and enter their username. The form works well as it will populate the clinical table. What I want to do is allow the student select multiple clinical dates and shifts, and submit the form.

The current table structure is username, shift, date and clinical center.  Will php allow me to make multiple entries for a single user to the db without having to alter the table to include more fields for each clinical date and shift chosen? I would prefer a single entry for each clinical date choosen.

I've scoured many php sites and can't find anything closely related to what I want to do.

Many thanks.

Dave
Link to comment
Share on other sites

My bad, I should have mentioned that each day on the calendar will have a checkbox for each clinical shift.  Say a student selects the same shift monday through friday for the entire month at the same hospital.  What I'm trying to do is populate the db with a separate entry for each shift that student selected.
My reasoning for a separate entry for each shift, each student has a portal page they sign into. When they sign in, their personal page will display their current clinical schedule and a flashing reminder on the day of their clinical, plus other data.

Hope this clarifies things.
Link to comment
Share on other sites

See if this is what you want. You will have to change the table and field names. Thanks to phpfreaks for the calender script!!!

Sorry just did the whole damn page :)
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Hello!</title>
</head>
<style type="text/css">
<!--
.table.calendar {border: 1px solid #000000; border-collapse: collapse; color: #000000; background: #FFFFFF; }
.td.today { border: 1px solid white; color: #000000; background: #EFEFEF; font-weight: bold;}
.td.monthdays {border: 1px solid #434470; color: #000000; background: #FFFFFFF; }
.td.nonmonthdays { border: 1px solid white; color: #000000; background: #EFEFEF;}
-->
</style>
<body>
<?php
if(isset($_GET['submit'])){
require('config.php');
include('includes/mysql.php');

$name = $_GET['uname'];
$shift = $_GET['shift'];
$ccenter = $_GET['ccenter'];

foreach($_GET as $key => $val){
  if(substr($key, 0, 4) == "date"){
    $sdate = date("Y-m-d", $val);
    $sql = "INSERT INTO yourtable SET
            namefield = '$name',
            shiftfield = '$shift',
            clinicalfield = '$ccenter',
            datefield = '$sdate'";
    mysql_query($sql) or die (mysql_error());

  }

}

} else {

?>
<form method=GET action="<?=$_SERVER['PHP_SELF']?>">
  <table width=400 align=center>
    <tr>
      <td WIDTH=400>Name</td>
      <td WIDTH=400><input type=text name=uname /></td>
    </tr>
    <tr>
      <td>Shift</td>
      <td><input type=text name=shift /></td>
    </tr>
    <tr>
      <td>Clinical center</td>
      <td><input type=text name=ccenter /></td>
    </tr>
    <tr>
      <td colspan=2 align=center>
<?php
error_reporting('0');
ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script

if(!isset($_REQUEST['date'])){
  $date = mktime(0,0,0,date('m'), date('d'), date('Y'));
} else {
  $date = $_REQUEST['date'];
}

$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);

// Get the first day of the month
$month_start = mktime(0,0,0,$month, 1, $year);

// Get friendly month name
$month_name = date('M', $month_start);

// Figure out which day of the week
// the month starts on.
$month_start_day = date('D', $month_start);

switch($month_start_day){
    case "Sun": $offset = 0; break;
    case "Mon": $offset = 1; break;
    case "Tue": $offset = 2; break;
    case "Wed": $offset = 3; break;
    case "Thu": $offset = 4; break;
    case "Fri": $offset = 5; break;
    case "Sat": $offset = 6; break;
}

// determine how many days are in the last month.
if($month == 1){
  $num_days_last = cal_days_in_month(0, 12, ($year -1));
} else {
  $num_days_last = cal_days_in_month(0, ($month -1), $year);
}
// determine how many days are in the current month.
$num_days_current = cal_days_in_month(0, $month, $year);

// Build an array for the current days
// in the month
for($i = 1; $i <= $num_days_current; $i++){
    $num_days_array[] = $i;
}

// Build an array for the number of days
// in last month
for($i = 1; $i <= $num_days_last; $i++){
    $num_days_last_array[] = $i;
}

// If the $offset from the starting day of the
// week happens to be Sunday, $offset would be 0,
// so don't need an offset correction.

if($offset > 0){
    $offset_correction = array_slice($num_days_last_array, -$offset, $offset);
    $new_count = array_merge($offset_correction, $num_days_array);
    $offset_count = count($offset_correction);
}

// The else statement is to prevent building the $offset array.
else {
    $offset_count = 0;
    $new_count = $num_days_array;
}

// count how many days we have with the two
// previous arrays merged together
$current_num = count($new_count);

// Since we will have 5 HTML table rows (TR)
// with 7 table data entries (TD)
// we need to fill in 35 TDs
// so, we will have to figure out
// how many days to appened to the end
// of the final array to make it 35 days.


if($current_num > 35){
  $num_weeks = 6;
  $outset = (42 - $current_num);
} elseif($current_num < 35){
  $num_weeks = 5;
  $outset = (35 - $current_num);
}
if($current_num == 35){
  $num_weeks = 5;
  $outset = 0;
}
// Outset Correction
for($i = 1; $i <= $outset; $i++){
  $new_count[] = $i;
}

// Now let's "chunk" the $all_days array
// into weeks. Each week has 7 days
// so we will array_chunk it into 7 days.
$weeks = array_chunk($new_count, 7);


// Build Previous and Next Links
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 1){
  $previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
  $previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><< Prev</a>";

$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 12){
  $next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
  $next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">Next >></a>";

// Build the heading portion of the calendar table
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" class=\"calendar\">\n".
    "<tr>\n".
    "<td colspan=\"7\">\n".
    "<table align=\"center\">\n".
    "<tr>\n".
    "<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
    "<td colspan=\"3\" width=\"150\" align=\"center\">$month_name $year</td>\n".
    "<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n".
    "</tr>\n".
    "</table>\n".
    "</td>\n".
    "<tr>\n".
    "<td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td>\n".
    "</tr>\n";

// Now we break each key of the array
// into a week and create a new table row for each
// week with the days of that week in the table data

$i = 0;
foreach($weeks AS $week){
      echo "<tr>\n";
      foreach($week as $d){
        if($i < $offset_count){
          $ndate = mktime(0,0,0,$month -1,$d,$year);
            $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".$ndate."\">$d</a>";
            echo "<td class=\"nonmonthdays\">$day_link<br><input type=checkbox name=date$i value=$ndate></td>\n";
        }
        if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
            $cdate = mktime(0,0,0,$month,$d,$year);
            $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".$cdate."\">$d</a>";
          if($date == $cdate){
              echo "<td class=\"today\">$d<br><input type=checkbox name=date$i value=$cdate></td>\n";
          } else {
              echo "<td class=\"days\">$day_link<br><input type=checkbox name=date$i value=$cdate></td>\n";
          }
        } elseif(($outset > 0)) {
            if(($i >= ($num_weeks * 7) - $outset)){
              $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
              echo "<td class=\"nonmonthdays\">$day_link</td>\n";
          }
        }
        $i++;
      }
      echo "</tr>\n";
}

// Close out your table and that's it!
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table>';
?>
</td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit name=submit value=submit /></td></tr>
</table>
</form>
<?php
}
?>
</body>
</html>[/code]


Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.