/    Sign up×
Community /Pin to ProfileBookmark

help – php calendar!

hey,

I have a dropdown menu of student id’s. I then want to it link to my calendar php page, where it will highlight the days that that student logined in on.

I have a table (registrations) with with the student id’s (StudID) and the date (RegDate) of the student loginning in.

I have the calendar working it display highlight days when someone has loginned in but I would like it to display it for just one student, that you pick from the drop down menu.

[CODE][B]dropdown.php[/B]<body>

<?php
$db = mysql_connect(“localhost”, “root”, “root”);
mysql_select_db(“reg”,$db);
$result = mysql_query(“SELECT * FROM Users”,$db);
?>
<form method=”post” action=”http://localhost:8080/4/results.php”>
<SELECT NAME=”S1″>
<?php
while ($myrow = mysql_fetch_row($result)) {
printf(“<OPTION VALUE=%s> %s n”,
$myrow[1],$myrow[0]);
}
?>
</SELECT>
<input type=”submit”>
</form>
</body>

[B]results.php[/B]

<?php

$conn = mysql_pconnect(“localhost”,”root”,”root”);

$db = mysql_select_db(“reg”);

$dateComponents = getdate();

$month = $dateComponents[‘mon’];
$year = $dateComponents[‘year’];

$query = “SELECT dayofmonth(regDate) as regDate
FROM registrations”;

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$dateArray[] = $row[‘regDate’];

}

echo build_calendar($month,$year,$dateArray);

if (isset ($_GET[‘date’])) {

$date = $_GET[‘date’];

} else {

$date = date(“Y-m-d”);

}

echo “<p><table width=’350′><tr><td>”;

$blogQuery = “SELECT StudID
FROM registrations WHERE regDate = ‘$date'”;

$blogResult = mysql_query($blogQuery);

if (mysql_numrows($blogResult) > 0) {

while (list($StudID) =
mysql_fetch_row($blogResult)) {

echo “”;

}

} else {

echo “This months attendance”;

}

echo “</td></tr></table></p>”;

?>

[B]cal01.php[/B]

<?php

function build_calendar($month,$year,$dateArray) {

// Create array containing abbreviations of days of week.
$daysOfWeek = array(‘Su’,’Mo’,’Tu’,’We’,’Th’,’Fr’,’Sa’);

// What is the first day of the month in question?
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);

// How many days does this month contain?
$numberDays = date(‘t’,$firstDayOfMonth);

// Retrieve some information about the first day of the
// month in question.
$dateComponents = getdate($firstDayOfMonth);

// What is the name of the month in question?
$monthName = $dateComponents[‘month’];

// What is the index value (0-6) of the first day of the
// month in question.
$dayOfWeek = $dateComponents[‘wday’];

// Create the table tag opener and day headers

$calendar = “<table class=’calendar’>”;
$calendar .= “<caption>$monthName, $year</caption>”;
$calendar .= “<tr>”;

// Create the calendar headers

foreach($daysOfWeek as $day) {
$calendar .= “<th class=’header’>$day</th>”;
}

// Create the rest of the calendar

// Initiate the day counter, starting with the 1st.

$currentDay = 1;

$calendar .= “</tr><tr>”;

// The variable $dayOfWeek is used to
// ensure that the calendar
// display consists of exactly 7 columns.

if ($dayOfWeek > 0) {
$calendar .= “<td colspan=’$dayOfWeek’>&nbsp;</td>”;
}

while ($currentDay <= $numberDays) {

// Seventh column (Saturday) reached. Start a new row.

if ($dayOfWeek == 7) {

$dayOfWeek = 0;
$calendar .= “</tr><tr>”;

}

// Is the $currentDay a member of $dateArray? If so,
// the day should be linked.

if (in_array($currentDay,$dateArray)) {

$date = “$year-$month-$currentDay”;

$calendar .= “<td class=’linkedday’>
$currentDay</td>”;

// $currentDay is not a member of $dateArray.

} else {

$calendar .= “<td class=’day’>$currentDay</td>”;

}

// Increment counters

$currentDay++;
$dayOfWeek++;

}

// Complete the row of the last week in month, if necessary

if ($dayOfWeek != 7) {

$remainingDays = 7 – $dayOfWeek;
$calendar .= “<td colspan=’$remainingDays’>&nbsp;</td>”;

}

$calendar .= “</table>”;

return $calendar;

}

?> [/CODE]

I’m guessing I need to insert a statement similair to this;

$result = mysql_query(“SELECT * FROM registrations WHERE StudID='”.$_POST[‘S1’].”‘”,$db);

but when I insert this into the cal01.php file I just get errors.

Can anyone help please ?

thankyou.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@se86authorApr 17.2007 — I added in the following bit of code into the results.php file

$result = mysql_query("SELECT * FROM registrations WHERE StudID='".$_POST['T4']."'",$db);

and these are the errors im getting;

Notice: Undefined index: T4 in C:phpweb4results2.php on line 35

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:phpweb4results2.php on line 35

Notice: Undefined variable: dateArray in C:phpweb4results2.php on line 37

Warning: in_array(): Wrong datatype for second argument in C:phpweb4cal02.php on line 68

please can anyone help?

?
Copy linkTweet thisAlerts:
@stephan_gerlachApr 17.2007 — Give this one a try. I have done a couple changes to it.

[code=php]dropdown.php<body>

<?php
$db = mysql_connect("localhost", "root", "root");
mysql_select_db("reg",$db);
$result = mysql_query("SELECT * FROM Users",$db);
?>
<form method="post" action="http://localhost:8080/4/results.php">
<SELECT NAME="S1">
<?php
while ($myrow = mysql_fetch_row($result)) {
printf("<option value="%s"> %s </option>n",
$myrow[1],$myrow[0]);
// IMPORTANT $myrow[1] has to be the student id
}
?>
</SELECT>
<input type="submit">
</form>
</body>

results.php

<?php

$conn = mysql_pconnect("localhost","root","root");

$db = mysql_select_db("reg");

$dateComponents = getdate();

$month = $dateComponents['mon'];
$year = $dateComponents['year'];

$query = "SELECT dayofmonth(regDate) as regDate
FROM registrations";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$dateArray[] = $row['regDate'];

}

echo build_calendar($month,$year,$dateArray);

if (isset ($_GET['date'])) {

$date = $_GET['date'];

} else {

$date = date("Y-m-d");

}

echo "<p><table width='350'><tr><td>";

$blogQuery = 'SELECT StudID
FROM registrations WHERE regDate = "'.$date'" AND StudID="'.$_POST['S1'].'";

$blogResult = mysql_query($blogQuery);

if (mysql_numrows($blogResult) > 0) {

while (list($StudID) =
mysql_fetch_row($blogResult)) {

echo "";

}

} else {

echo "This months attendance";

}

echo "</td></tr></table></p>";

?>

cal01.php

<?php

function build_calendar($month,$year,$dateArray) {

// Create array containing abbreviations of days of week.
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');

// What is the first day of the month in question?
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);

// How many days does this month contain?
$numberDays = date('t',$firstDayOfMonth);

// Retrieve some information about the first day of the
// month in question.
$dateComponents = getdate($firstDayOfMonth);

// What is the name of the month in question?
$monthName = $dateComponents['month'];

// What is the index value (0-6) of the first day of the
// month in question.
$dayOfWeek = $dateComponents['wday'];

// Create the table tag opener and day headers

$calendar = "<table class='calendar'>";
$calendar .= "<caption>$monthName, $year</caption>";
$calendar .= "<tr>";

// Create the calendar headers

foreach($daysOfWeek as $day) {
$calendar .= "<th class='header'>$day</th>";
}

// Create the rest of the calendar

// Initiate the day counter, starting with the 1st.

$currentDay = 1;

$calendar .= "</tr><tr>";

// The variable $dayOfWeek is used to
// ensure that the calendar
// display consists of exactly 7 columns.

if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>";
}

while ($currentDay <= $numberDays) {

// Seventh column (Saturday) reached. Start a new row.

if ($dayOfWeek == 7) {

$dayOfWeek = 0;
$calendar .= "</tr><tr>";

}

// Is the $currentDay a member of $dateArray? If so,
// the day should be linked.


if (in_array($currentDay,$dateArray)) {

$date = "$year-$month-$currentDay";

$calendar .= "<td class='linkedday'>
$currentDay</td>";

// $currentDay is not a member of $dateArray.

} else {

$calendar .= "<td class='day'>$currentDay</td>";

}







// Increment counters

$currentDay++;
$dayOfWeek++;

}

// Complete the row of the last week in month, if necessary

if ($dayOfWeek != 7) {

$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";

}

$calendar .= "</table>";

return $calendar;

}

?> [/code]
Copy linkTweet thisAlerts:
@MrCoderApr 17.2007 — [code=php]
$blogQuery = 'SELECT StudID

FROM registrations WHERE regDate = "'.$date'" AND StudID="'.$_POST['S1'].'";
[/code]


Should be..

[code=php]
$blogQuery = 'SELECT StudID

FROM registrations WHERE regDate = "'.$date.'" AND StudID="'.$_POST['S1'].'"';
[/code]


Not read the rest, just noticed that while skimming.

btw, how do you know if it works if you didn't test it?
Copy linkTweet thisAlerts:
@se86authorApr 18.2007 — thanks for your help, i've managed to get the calendar to display with no errors but it doesn't highlight the days in the calendar that the id selected from the dropdown menu, it is highlighting all days from within the database for all id's.

is there some extra piece of code I am missing that i need to insert into one of the files to make the highlighted days only show for the dates in the database?

any help would be great.

thankyou ?
×

Success!

Help @se86 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...