/    Sign up×
Community /Pin to ProfileBookmark

calendar link

Hi Below is code that displays a calendar which offers links for each day of the week. which opens a form to add information to a data base.

I’m trying to add a link undereach date where there is a schedualed event.

so far i have this which does nothing

[code=php]
include ‘db.php’;
$dlink = mysql_query(“SELECT * FROM calendar WHERE event_date = ‘$linkdate'”);
while ($row=mysql_fetch_assoc($dlink)){

$description = $row[‘event_description’];

echo “<a href=results.php?eventid=$link_date> $description </a></td>”;

}
[/code]

complete calendar code

[code=php]
<?php
echo ”
<html>
<head>
<title>Calendar</title>
<body bgcolor=#FFFFFF>
<center>”;

// Check for a Month Change submission
if ($_POST) {

// Subtract one from the month for previous, add one for next

if ($_POST[“submit”] == “Prev”) {
$_POST[“month_now”]–;
} else {
$_POST[“month_now”]++; }

$date = getdate(mktime(0,0,0,
$_POST[“month_now”],1,
$_POST[“year_now”]));

} else {
$date = getdate();
}

$month_num = $date[“mon”];
$month_name = $date[“month”];
$year = $date[“year”];
$date_today = getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day = $date_today[“wday”];
$cont = true;
$today = 27;

while (($today <= 32) && ($cont)) {
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));

if ($date_today[“mon”] != $month_num) {
$lastday = $today – 1;
$cont = false;
}

$today++;
}

// allow for form submission to the script for forward and backwards

echo”
<form method=’POST’ name=’calendar’ action=’cal.php’>

<input type=’hidden’ name=’month_now’ value=’$month_num’>
<input type=’hidden’ name=’year_now’ value=’$year’>
<table width=’200′>
<tr><td><input type=’submit’ name=’submit’ value=’Prev’></td>
<td align=right><input
type=’submit’ name=’button’ value=’Next’></td>
</tr>
</table>
</form>

<table width=’160′ border=’1′ cellspacing=0 cellpadding=2>
<tr><td colspan=’7′>$month_name $year</td></tr>
<tr><td>Su</td><td>M</td><td>T</td><td>W</td><td>Th</td><td>F</td><td>Sat</td></
tr>”;

// begin placement of days according to their beginning weekday

$day = 1;
$wday = $first_week_day;
$firstweek = true;
while ( $day <= $lastday) {
if ($firstweek) {
echo “<TR>”;
for ($i=1; $i<=$first_week_day; $i++) {

echo “<TD> </td>”;
}
$firstweek = false;
}
if ($wday==0) {
echo “<tr>”;
}

// make each day linkable to the following result.php page

if ( intval($month_num) < 10) { $new_month_num = “0$month_num”; }
elseif (intval($month_num) >= 10) { $new_month_num = $month_num; }
if ( intval($day) < 10) { $new_day = “0$day”; }
elseif (intval($day) >= 10) { $new_day = $day; }
$link_date = “$year-$new_month_num-$new_day”;

// add some color and make todays dat stand out
$today_year = date(“Y”);
$today_month = date(“F”);
$today_day = date(“j”);

if($day == $today_day && $month_name ==
$today_month && $year == $today_year)
$colour = orange;
else
$colour = silver;
echo “<td align=center bgcolor=$colour><a href=results.php?eventid=$link_date> $day </a></td>”;

// show event description
include ‘db.php’;
$dlink = mysql_query(“SELECT * FROM calendar WHERE event_date = ‘$linkdate'”);
while ($row=mysql_fetch_assoc($dlink)){

$description = $row[‘event_description’];

echo “<a href=results.php?eventid=$link_date> $description </a></td>”;

}

if ($wday==6) {
echo “</tr>n”;
}

$wday++;
$wday = $wday % 7;
$day++;
}
echo”
</table>
</body>
</html>
“;
?>

[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@zoromaskcomingAug 21.2006 —  echo "<a href=results.php?eventid=$link_date> $description </a></td>";

[/QUOTE]

well, I see no errors in the posted first code, except the html error, you are closing table cell, but where the the opening?

[CODE]echo "<td><a href=results.php?eventid=$link_date> $description </a></td>";[/CODE]

if this doesn't work, check the entry if they come from the database correctly or not, in the mysql_query(...) add or die ('error in sql'.mysql_error());

and also echo the results in row, to make sure they are working, after that we can turn to different part of the code. but I assume it might be just the html error.
Copy linkTweet thisAlerts:
@kprocauthorAug 21.2006 — Thanks for the info, I made the changes and still the same result. nothing happens. the echo statement returns nothing.


I believe the issue is the variable that I'm testing against event_date. I need to somehow create a loop that goes throught the days of the month.
Copy linkTweet thisAlerts:
@kprocauthorAug 21.2006 — Hi I have been trying different things and no luck.

With the variables within the code I posted I need to create a variable that loop through each day of the month which will be used to seach table.

The date format in the table is 2006-08-21

variables I think should be used to create date
[code=php]


$month_num = $date["mon"];
$month_name = $date["month"];
$year = $date["year"];
$date_today = getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day = $date_today["wday"];
$cont = true;
$today = 27;

while (($today <= 32) && ($cont)) {
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));

[/code]
Copy linkTweet thisAlerts:
@kprocauthorAug 21.2006 — I have figured out how to get the days of the month assigned to a variable, know I need to determine how to assign the results to an array

the could the displays the dates

[code=php]echo $year.'-'.$month_num.'-'.$day;[/code]

I want the echo to be a variable


[code=php]
$day = 1;
$wday = $first_week_day;
$firstweek = true;
while ( $day <= $lastday) {
echo $year.'-'.$month_num.'-'.$day;

if ($firstweek) {
echo "<TR>";
for ($i=1; $i<=$first_week_day; $i++) {

echo "<TD> </td>";
}
$firstweek = false;
}
if ($wday==0) {
echo "<tr>";


}
[/code]
Copy linkTweet thisAlerts:
@kprocauthorAug 21.2006 — Hi

I relpy Once again

$month_day returns the values as an array. the way I have the below setup will not echo anything. if i echo $month_day the value returned is array.

notice how the array number are [0] and [1] should it not be [0] to [??] the ?? being the last number in the array in this case [30].



=> 2006-8-1 ) Array ( [0] => 2006-8-2 ) Array ( [0] => 2006-8-3 ) Array ( [0] => 2006-8-4 ) Array ( [0] => 2006-8-5 ) Array ( [0] => 2006-8-6 ) Array ( [0] => 2006-8-7 ) Array ( [0] => 2006-8-8 ) Array ( [0] => 2006-8-9 ) Array ( [0] => 2006-8-10 ) Array ( [0] => 2006-8-11 ) Array ( [0] => 2006-8-12 ) Array ( [0] => 2006-8-13 ) Array ( [0] => 2006-8-14 ) Array ( [0] => 2006-8-15 ) Array ( [0] => 2006-8-16 ) Array ( [0] => 2006-8-17 ) Array ( [0] => 2006-8-18 ) Array ( [0] => 2006-8-19 ) Array ( [0] => 2006-8-20 ) Array ( [0] => 2006-8-21 ) Array ( [0] => 2006-8-22 ) Array ( [0] => 2006-8-23 ) Array ( [0] => 2006-8-24 ) Array ( [0] => 2006-8-25 ) Array ( [0] => 2006-8-26 ) Array ( [0] => 2006-8-27 ) Array ( [0] => 2006-8-28 ) Array ( [0] => 2006-8-29 ) Array ( [0] => 2006-8-30 ) Array ( [0] => 2006-8-31 )

August 2006


to accomplish my goal i need to loop through each value in the array and check table column event_date for a match.

any advice help is great

[code=php]
$month_day = explode(",",$month_d,-1);

$cal_description = mysql_query("SELECT * FROM calendar WHERE event_date = $month_day") or die (mysql_error());

while($r=mysql_fetch_assoc($cal_description)) {

$description = $r['event_description'];

echo $description;

}
[/code]
×

Success!

Help @kproc 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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