This is a discussion on simple events calendar using mysql within the PHP Language forums, part of the PHP Programming Forums category; Hello all, this may sound very elementary and i am sorry for that. I am struggling with a very simple ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello all, this may sound very elementary and i am sorry for that. I
am struggling with a very simple calendar for my web site. I already have the database set up and the admin to input events and i have a way to display the calendar. the problem i am having is querying and linking my events from the database to the calendar. I have looked at all the stock calendars out there and what they offer i do not need. i have gone through what seems to be every tutorial for calendars but none of which teach how to query and create the links. here is the code to display the calendar: $date =time () ; $day = date('d', $date) ; $month = date('m', $date) ; $year = date('Y', $date) ; $first_day = mktime(0,0,0,$month, 1, $year) ; $title = date('F', $first_day) ; $day_of_week = date('D', $first_day) ; switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year) ; echo "<table border=1 width=294>"; echo "<tr><th colspan=7> $title $year </th></tr>"; echo "<tr><td class=month width=42>Sun</td><td class=month width=42>Mon</td><td class=month width=42>Tue</td><td class=month width=42>Wed</td><td class=month width=42>Thu</td><td class=month width=42>Fri</td><td class=month width=42>Sat</td></tr>"; $day_count = 1; echo "<tr>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ( $day_num <= $days_in_month ) { echo "<td> $day_num </td>"; $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> If anyone can please show me how to query and link my events i would really appreciate it. God bless jsd219 |
|
|||
|
"jsd219" <info@musiclanerecording.com> wrote in message news:1193798764.191193.112080@57g2000hsv.googlegro ups.com... > Hello all, this may sound very elementary and i am sorry for that. I > am struggling with a very simple calendar for my web site. I already > have the database set up and the admin to input events and i have a > way to display the calendar. the problem i am having is querying and > linking my events from the database to the calendar. I have looked at > all the stock calendars out there and what they offer i do not need. i > have gone through what seems to be every tutorial for calendars but > none of which teach how to query and create the links. here is the > code to display the calendar: > > $date =time () ; > > $day = date('d', $date) ; > $month = date('m', $date) ; > $year = date('Y', $date) ; > > $first_day = mktime(0,0,0,$month, 1, $year) ; > > $title = date('F', $first_day) ; > > $day_of_week = date('D', $first_day) ; > > switch($day_of_week){ > case "Sun": $blank = 0; break; > case "Mon": $blank = 1; break; > case "Tue": $blank = 2; break; > case "Wed": $blank = 3; break; > case "Thu": $blank = 4; break; > case "Fri": $blank = 5; break; > case "Sat": $blank = 6; break; > } > > $days_in_month = cal_days_in_month(0, $month, $year) ; > > echo "<table border=1 width=294>"; > echo "<tr><th colspan=7> $title $year </th></tr>"; > echo "<tr><td class=month width=42>Sun</td><td class=month > width=42>Mon</td><td class=month width=42>Tue</td><td class=month > width=42>Wed</td><td class=month width=42>Thu</td><td class=month > width=42>Fri</td><td class=month width=42>Sat</td></tr>"; > > $day_count = 1; > > echo "<tr>"; > > while ( $blank > 0 ) > { > echo "<td></td>"; > $blank = $blank-1; > $day_count++; > } > > $day_num = 1; > > while ( $day_num <= $days_in_month ) > { > echo "<td> $day_num </td>"; > $day_num++; > $day_count++; > > if ($day_count > 7) > { > echo "</tr><tr>"; > $day_count = 1; > } > } > > while ( $day_count >1 && $day_count <=7 ) > { > echo "<td> </td>"; > $day_count++; > } > > echo "</tr></table>"; > > ?> > > If anyone can please show me how to query and link my events i would > really appreciate it. > > God bless > jsd219 Just what is it that you are "querying"? IOW, what is it that you want to have happen? Shelly |
|
|||
|
On Oct 31, 6:33 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote:
> "jsd219" <i...@musiclanerecording.com> wrote in message > > news:1193798764.191193.112080@57g2000hsv.googlegro ups.com... > > > > > Hello all, this may sound very elementary and i am sorry for that. I > > am struggling with a very simple calendar for my web site. I already > > have the database set up and the admin to input events and i have a > > way to display the calendar. the problem i am having is querying and > > linking my events from the database to the calendar. I have looked at > > all the stock calendars out there and what they offer i do not need. i > > have gone through what seems to be every tutorial for calendars but > > none of which teach how to query and create the links. here is the > > code to display the calendar: > > > $date =time () ; > > > $day = date('d', $date) ; > > $month = date('m', $date) ; > > $year = date('Y', $date) ; > > > $first_day = mktime(0,0,0,$month, 1, $year) ; > > > $title = date('F', $first_day) ; > > > $day_of_week = date('D', $first_day) ; > > > switch($day_of_week){ > > case "Sun": $blank = 0; break; > > case "Mon": $blank = 1; break; > > case "Tue": $blank = 2; break; > > case "Wed": $blank = 3; break; > > case "Thu": $blank = 4; break; > > case "Fri": $blank = 5; break; > > case "Sat": $blank = 6; break; > > } > > > $days_in_month = cal_days_in_month(0, $month, $year) ; > > > echo "<table border=1 width=294>"; > > echo "<tr><th colspan=7> $title $year </th></tr>"; > > echo "<tr><td class=month width=42>Sun</td><td class=month > > width=42>Mon</td><td class=month width=42>Tue</td><td class=month > > width=42>Wed</td><td class=month width=42>Thu</td><td class=month > > width=42>Fri</td><td class=month width=42>Sat</td></tr>"; > > > $day_count = 1; > > > echo "<tr>"; > > > while ( $blank > 0 ) > > { > > echo "<td></td>"; > > $blank = $blank-1; > > $day_count++; > > } > > > $day_num = 1; > > > while ( $day_num <= $days_in_month ) > > { > > echo "<td> $day_num </td>"; > > $day_num++; > > $day_count++; > > > if ($day_count > 7) > > { > > echo "</tr><tr>"; > > $day_count = 1; > > } > > } > > > while ( $day_count >1 && $day_count <=7 ) > > { > > echo "<td> </td>"; > > $day_count++; > > } > > > echo "</tr></table>"; > > > ?> > > > If anyone can please show me how to query and link my events i would > > really appreciate it. > > > God bless > > jsd219 > > Just what is it that you are "querying"? IOW, what is it that you want to > have happen? > > Shelly the calendar is for a mission group, it is mission trips that are in the database and i would like the calendar to display the trip title on the appropriate date as a link that opens a popup window with the trip information. my database has is: name: calendar fields: id, title, date, text God bless jason |
|
|||
|
jsd219 wrote:
> On Oct 31, 6:33 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote: >> "jsd219" <i...@musiclanerecording.com> wrote in message >> >> news:1193798764.191193.112080@57g2000hsv.googlegro ups.com... >> >> >> >>> Hello all, this may sound very elementary and i am sorry for that. I >>> am struggling with a very simple calendar for my web site. I already >>> have the database set up and the admin to input events and i have a >>> way to display the calendar. the problem i am having is querying and >>> linking my events from the database to the calendar. I have looked >>> at all the stock calendars out there and what they offer i do not >>> need. i have gone through what seems to be every tutorial for >>> calendars but none of which teach how to query and create the >>> links. here is the code to display the calendar: >> >>> $date =time () ; >> >>> $day = date('d', $date) ; >>> $month = date('m', $date) ; >>> $year = date('Y', $date) ; >> >>> $first_day = mktime(0,0,0,$month, 1, $year) ; >> >>> $title = date('F', $first_day) ; >> >>> $day_of_week = date('D', $first_day) ; >> >>> switch($day_of_week){ >>> case "Sun": $blank = 0; break; >>> case "Mon": $blank = 1; break; >>> case "Tue": $blank = 2; break; >>> case "Wed": $blank = 3; break; >>> case "Thu": $blank = 4; break; >>> case "Fri": $blank = 5; break; >>> case "Sat": $blank = 6; break; >>> } >> >>> $days_in_month = cal_days_in_month(0, $month, $year) ; >> >>> echo "<table border=1 width=294>"; >>> echo "<tr><th colspan=7> $title $year </th></tr>"; >>> echo "<tr><td class=month width=42>Sun</td><td class=month >>> width=42>Mon</td><td class=month width=42>Tue</td><td class=month >>> width=42>Wed</td><td class=month width=42>Thu</td><td class=month >>> width=42>Fri</td><td class=month width=42>Sat</td></tr>"; >> >>> $day_count = 1; >> >>> echo "<tr>"; >> >>> while ( $blank > 0 ) >>> { >>> echo "<td></td>"; >>> $blank = $blank-1; >>> $day_count++; >>> } >> >>> $day_num = 1; >> >>> while ( $day_num <= $days_in_month ) >>> { >>> echo "<td> $day_num </td>"; >>> $day_num++; >>> $day_count++; >> >>> if ($day_count > 7) >>> { >>> echo "</tr><tr>"; >>> $day_count = 1; >>> } >>> } >> >>> while ( $day_count >1 && $day_count <=7 ) >>> { >>> echo "<td> </td>"; >>> $day_count++; >>> } >> >>> echo "</tr></table>"; >> >>>> >> >>> If anyone can please show me how to query and link my events i would >>> really appreciate it. >> >>> God bless >>> jsd219 >> >> Just what is it that you are "querying"? IOW, what is it that you >> want to have happen? >> >> Shelly > > the calendar is for a mission group, it is mission trips that are in > the database and i would like the calendar to display the trip title > on the appropriate date as a link that opens a popup window with the > trip information. my database has is: > > name: calendar > fields: id, title, date, text Then do a query with $q = "select * from calendar where id=" . $id; where $id is the one you want. Then work on the result to fetch the values of each field. Then use an echo statement enclosed with <?php ?> for the value of the particular field in the html document. Shelly |
|
|||
|
On Oct 31, 10:57 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote:
> jsd219 wrote: > > On Oct 31, 6:33 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote: > >> "jsd219" <i...@musiclanerecording.com> wrote in message > > >>news:1193798764.191193.112080@57g2000hsv.googleg roups.com... > > >>> Hello all, this may sound very elementary and i am sorry for that. I > >>> am struggling with a very simple calendar for my web site. I already > >>> have the database set up and the admin to input events and i have a > >>> way to display the calendar. the problem i am having is querying and > >>> linking my events from the database to the calendar. I have looked > >>> at all the stock calendars out there and what they offer i do not > >>> need. i have gone through what seems to be every tutorial for > >>> calendars but none of which teach how to query and create the > >>> links. here is the code to display the calendar: > > >>> $date =time () ; > > >>> $day = date('d', $date) ; > >>> $month = date('m', $date) ; > >>> $year = date('Y', $date) ; > > >>> $first_day = mktime(0,0,0,$month, 1, $year) ; > > >>> $title = date('F', $first_day) ; > > >>> $day_of_week = date('D', $first_day) ; > > >>> switch($day_of_week){ > >>> case "Sun": $blank = 0; break; > >>> case "Mon": $blank = 1; break; > >>> case "Tue": $blank = 2; break; > >>> case "Wed": $blank = 3; break; > >>> case "Thu": $blank = 4; break; > >>> case "Fri": $blank = 5; break; > >>> case "Sat": $blank = 6; break; > >>> } > > >>> $days_in_month = cal_days_in_month(0, $month, $year) ; > > >>> echo "<table border=1 width=294>"; > >>> echo "<tr><th colspan=7> $title $year </th></tr>"; > >>> echo "<tr><td class=month width=42>Sun</td><td class=month > >>> width=42>Mon</td><td class=month width=42>Tue</td><td class=month > >>> width=42>Wed</td><td class=month width=42>Thu</td><td class=month > >>> width=42>Fri</td><td class=month width=42>Sat</td></tr>"; > > >>> $day_count = 1; > > >>> echo "<tr>"; > > >>> while ( $blank > 0 ) > >>> { > >>> echo "<td></td>"; > >>> $blank = $blank-1; > >>> $day_count++; > >>> } > > >>> $day_num = 1; > > >>> while ( $day_num <= $days_in_month ) > >>> { > >>> echo "<td> $day_num </td>"; > >>> $day_num++; > >>> $day_count++; > > >>> if ($day_count > 7) > >>> { > >>> echo "</tr><tr>"; > >>> $day_count = 1; > >>> } > >>> } > > >>> while ( $day_count >1 && $day_count <=7 ) > >>> { > >>> echo "<td> </td>"; > >>> $day_count++; > >>> } > > >>> echo "</tr></table>"; > > >>> If anyone can please show me how to query and link my events i would > >>> really appreciate it. > > >>> God bless > >>> jsd219 > > >> Just what is it that you are "querying"? IOW, what is it that you > >> want to have happen? > > >> Shelly > > > the calendar is for a mission group, it is mission trips that are in > > the database and i would like the calendar to display the trip title > > on the appropriate date as a link that opens a popup window with the > > trip information. my database has is: > > > name: calendar > > fields: id, title, date, text > > Then do a query with > $q = "select * from calendar where id=" . $id; > where $id is the one you want. Then work on the result to fetch the values > of each field. Then use an echo statement enclosed with <?php ?> for the > value of the particular field in the html document. > > Shelly my apologies, I can do the query fine the problem I am having is I do not know how to use the loop for the days to pull the results from the query. :-) not sure if that made since. in other words, where and what would i put in the code to make $day_num link to a trip? God bless jason |
|
|||
|
On Oct 31, 10:57 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote:
> jsd219 wrote: > > On Oct 31, 6:33 am, "Shelly" <sheldonlg.n...@asap-consult.com> wrote: > >> "jsd219" <i...@musiclanerecording.com> wrote in message > > >>news:1193798764.191193.112080@57g2000hsv.googleg roups.com... > > >>> Hello all, this may sound very elementary and i am sorry for that. I > >>> am struggling with a very simple calendar for my web site. I already > >>> have the database set up and the admin to input events and i have a > >>> way to display the calendar. the problem i am having is querying and > >>> linking my events from the database to the calendar. I have looked > >>> at all the stock calendars out there and what they offer i do not > >>> need. i have gone through what seems to be every tutorial for > >>> calendars but none of which teach how to query and create the > >>> links. here is the code to display the calendar: > > >>> $date =time () ; > > >>> $day = date('d', $date) ; > >>> $month = date('m', $date) ; > >>> $year = date('Y', $date) ; > > >>> $first_day = mktime(0,0,0,$month, 1, $year) ; > > >>> $title = date('F', $first_day) ; > > >>> $day_of_week = date('D', $first_day) ; > > >>> switch($day_of_week){ > >>> case "Sun": $blank = 0; break; > >>> case "Mon": $blank = 1; break; > >>> case "Tue": $blank = 2; break; > >>> case "Wed": $blank = 3; break; > >>> case "Thu": $blank = 4; break; > >>> case "Fri": $blank = 5; break; > >>> case "Sat": $blank = 6; break; > >>> } > > >>> $days_in_month = cal_days_in_month(0, $month, $year) ; > > >>> echo "<table border=1 width=294>"; > >>> echo "<tr><th colspan=7> $title $year </th></tr>"; > >>> echo "<tr><td class=month width=42>Sun</td><td class=month > >>> width=42>Mon</td><td class=month width=42>Tue</td><td class=month > >>> width=42>Wed</td><td class=month width=42>Thu</td><td class=month > >>> width=42>Fri</td><td class=month width=42>Sat</td></tr>"; > > >>> $day_count = 1; > > >>> echo "<tr>"; > > >>> while ( $blank > 0 ) > >>> { > >>> echo "<td></td>"; > >>> $blank = $blank-1; > >>> $day_count++; > >>> } > > >>> $day_num = 1; > > >>> while ( $day_num <= $days_in_month ) > >>> { > >>> echo "<td> $day_num </td>"; > >>> $day_num++; > >>> $day_count++; > > >>> if ($day_count > 7) > >>> { > >>> echo "</tr><tr>"; > >>> $day_count = 1; > >>> } > >>> } > > >>> while ( $day_count >1 && $day_count <=7 ) > >>> { > >>> echo "<td> </td>"; > >>> $day_count++; > >>> } > > >>> echo "</tr></table>"; > > >>> If anyone can please show me how to query and link my events i would > >>> really appreciate it. > > >>> God bless > >>> jsd219 > > >> Just what is it that you are "querying"? IOW, what is it that you > >> want to have happen? > > >> Shelly > > > the calendar is for a mission group, it is mission trips that are in > > the database and i would like the calendar to display the trip title > > on the appropriate date as a link that opens a popup window with the > > trip information. my database has is: > > > name: calendar > > fields: id, title, date, text > > Then do a query with > $q = "select * from calendar where id=" . $id; > where $id is the one you want. Then work on the result to fetch the values > of each field. Then use an echo statement enclosed with <?php ?> for the > value of the particular field in the html document. > > Shelly My appologies, i know how to do the query but i do not know how to tell the code to display the title and a link to a trip that matches the date. in other words where in the code below do i say ok, now that the calendar is displayed, if 10/31/2007 has a trip in the database with the same date display the trip title and link it to open a popup window with the trip details? echo "<table border=1 width=294>"; echo "<tr><th colspan=7> $title $year </th></tr>"; echo "<tr><td class=month width=42>Sun</td><td class=month width=42>Mon</td><td class=month width=42>Tue</td><td class=month width=42>Wed</td><td class=month width=42>Thu</td><td class=month width=42>Fri</td><td class=month width=42>Sat</td></tr>"; //This counts the days in the week, up to 7 $day_count = 1; echo "<tr>"; //first we take care of those blank days while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } //sets the first day of the month to 1 $day_num = 1; //count up the days, untill we've done all of them in the month while ( $day_num <= $days_in_month ) { echo "<td> $day_num </td>"; $day_num++; $day_count++; //Make sure we start a new row every week if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Finaly we finish out the table with some blank details if needed while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; God bless jason |
|
|||
|
jsd219 wrote:
> My appologies, i know how to do the query but i do not know how to > tell the code to display the title and a link to a trip that matches > the date. in other words where in the code below do i say ok, now that > the calendar is displayed, if 10/31/2007 has a trip in the database You don't! What I mean by that it is not "now that the calendar is displayed,". You have to put it in AS you are building your display! In other words, when you do your query, have it ordered by date (ORDER BY the_date_field). Then build an array with all those rows. Now, as you are going about building the display of your calendar, check the date against the next one in the array. If it matches, then do an echo 'value="' . $whatever_info_you_want_to_appear_here . '"'; (that last was single-double-single quotes). and increment your position in the array so that the next time you check the date it will be the next one in the array. (Of course, stop all this checking once you have done all the elements in the array so that you are not going to get an out-of-bounds problem). Do you understand now? Shelly |
|
|||
|
On Oct 31, 12:10 pm, "Shelly" <sheldonlg.n...@asap-consult.com> wrote:
> jsd219 wrote: > > My appologies, i know how to do the query but i do not know how to > > tell the code to display the title and a link to a trip that matches > > the date. in other words where in the code below do i say ok, now that > > the calendar is displayed, if 10/31/2007 has a trip in the database > > You don't! What I mean by that it is not "now that the calendar is > displayed,". You have to put it in AS you are building your display! > > In other words, when you do your query, have it ordered by date (ORDER BY > the_date_field). Then build an array with all those rows. Now, as you are > going about building the display of your calendar, check the date against > the next one in the array. If it matches, then do an > > echo 'value="' . $whatever_info_you_want_to_appear_here . '"'; (that last > was single-double-single quotes). > > and increment your position in the array so that the next time you check the > date it will be the next one in the array. (Of course, stop all this > checking once you have done all the elements in the array so that you are > not going to get an out-of-bounds problem). > > Do you understand now? > > Shelly Please forgive my ignorance but i can not wrap my head around this. is what you are saying; query everything from the table and order it by date? i don't understand the . $id part. God bless jason |
|
|||
|
jsd219 wrote:
> On Oct 31, 12:10 pm, "Shelly" <sheldonlg.n...@asap-consult.com> wrote: >> jsd219 wrote: >>> My appologies, i know how to do the query but i do not know how to >>> tell the code to display the title and a link to a trip that matches >>> the date. in other words where in the code below do i say ok, now >>> that the calendar is displayed, if 10/31/2007 has a trip in the >>> database >> >> You don't! What I mean by that it is not "now that the calendar is >> displayed,". You have to put it in AS you are building your display! >> >> In other words, when you do your query, have it ordered by date >> (ORDER BY the_date_field). Then build an array with all those rows. >> Now, as you are going about building the display of your calendar, >> check the date against the next one in the array. If it matches, >> then do an >> >> echo 'value="' . $whatever_info_you_want_to_appear_here . '"'; >> (that last was single-double-single quotes). >> >> and increment your position in the array so that the next time you >> check the date it will be the next one in the array. (Of course, >> stop all this checking once you have done all the elements in the >> array so that you are not going to get an out-of-bounds problem). >> >> Do you understand now? >> >> Shelly > > Please forgive my ignorance but i can not wrap my head around this. is > what you are saying; query everything from the table and order it by > date? i don't understand the . $id part. Yes, that is exactly what I am saying. SQL will do that work for you and all you need do is add the ORDER BY clause. Since you cut where I said something about $id, I cannot help you other that to guess at what I said. I guess it was in building a query statement and I had a where clause of some field = something. Since the something would depend upon the value of a variable, I put that in. The dot operator is the append operator in PHP. Example: $foo = "jsd"; echo "Hello " . $foo; will output Hello jsd I suggest you do a little reading of the manual (www.php.net) or a tutorial www.w3schools.com for PHP and SQL. Shelly |