bobby317 Posted June 15, 2010 Share Posted June 15, 2010 Ok still working on my event calendar and have most of it working rather well What I am trying to do is when my calendar is creating the dates of the calendar and placing them into the table to also use that information to run a query to the database that will use the date field and add any events that are in the database to the correct date on the calendar. Not the whole event will be posted on the calendar but just at the name and then have it clickable to open it up to the description. I will post the form that collects the data and then the script that takes that data and places it into the database. After that will be the calendar script that creates the calendar. Please explain what you are doing so I may learn thanks everyone for all the help with this. Form for collecting event <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" /> <form name="addEvent" action="addevent.php" method="post"> <p> <label for="eventName">Event Name:</label> <span id="sprytextfield1"> <input type="text" name="eventName" maxlength="30" size="20" /> <span class="textfieldRequiredMsg">Please enter a event name.</span></span></p> <p> <label for="date">Date:</label> <select name="month" id="date"> <option>January</option> <option>February</option> <option>March</option> <option>April</option> <option>May</option> <option>June</option> <option>July</option> <option>August</option> <option>September</option> <option>October</option> <option>November</option> <option>December</option> </select> <select name="day" id="date"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select> <select name="year" id="date"> <option>2010</option> <option>2011</option> <option>2012</option> <option>2013</option> <option>2014</option> <option>2015</option> <option>2016</option> <option>2017</option> <option>2018</option> <option>2019</option> </select> </p> <p> <label for="startTime">Start Time:</label> <span id="sprytextfield2"> <input type="text" name="startTime" maxlength="10" size="10" /> <span class="textfieldRequiredMsg">Please enter a start time.</span><span class="textfieldInvalidFormatMsg">Invalid format. 00:00</span></span> <select name="timeOfDay1" id="startTime"> <option>AM</option> <option>PM</option> </select> </p> <p> <label for="endTime">End Time:</label> <span id="sprytextfield3"> <input type="text" name="endTime" maxlength="10" size="10" /> <span class="textfieldRequiredMsg">Please enter a end time.</span><span class="textfieldInvalidFormatMsg">Invalid format. 00:00</span></span> <select name="timeOfDay2" id="endTime"> <option>AM</option> <option>PM</option> </select> </p> <p> <label for="description">Description:</label> <span id="sprytextarea1"> <textarea name="description" rows="5" cols="50"></textarea> <span class="textareaRequiredMsg">Please enter your description.</span></span></p> <p> <input type="submit" value="Add Event" /> <input type="hidden" name="submit" value="true" /> </form> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "time"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "time"); var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1"); //--> </script> form that handles that info and places into database <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add Event</title> </head> <link href="eventMain.css" rel="stylesheet" type="text/css" /> <body> <?php //set addEventForm.html for include to a varibal $form = "addEventForm.html"; //Start code when form is submited if( !isset($_POST['submit'])) { include_once "$form"; } else { //Flag varible to track success $okay = TRUE; //Valadate name field if (empty($_POST['eventName'])) { print '<p class="error">Please the event your name.</p>'; $okay = FALSE; include_once "$form"; //Valadate date //Month } elseif (empty($_POST['month'])) { print '<p class="error">Please enter the month.</p>'; $okay = FALSE; include_once "$form"; //Day } elseif (empty($_POST['day'])) { print'<p class="eroor">Please enter the day.</p>'; $okay = FALSE; include_once "$form"; //Year } elseif (empty($_POST['year'])) { print'<p class="error">Please enter the year.</p>'; $okay = FALSE; include_once "$form"; //Valadate startTime } elseif (empty($_POST['startTime'])) { print'<p class="error">Please enter a start time.</p>'; $okay = FALSE; include_once "$form"; //Valadate endTime } elseif (empty($_POST['endTime'])) { print'<p class="error">Please enter a end time.</p>'; $okay = FALSE; include_once "$form"; //Valadate description } elseif (empty($_POST['description'])) { print'<p class="error">Please enter a description.</p>'; $okay = FALSE; include_once "$form"; //If $okay = TRUE orginize data and input into database } elseif ($okay == TRUE) { //remove white spaces create varables $eventName = trim($_POST['eventName']); $startTime = trim($_POST['startTime']); $timeOfDay1 = $_POST['timeOfDay1']; $endTime = trim($_POST['endTime']); $timeOfDay2 = $_POST['timeOfDay2']; $description = trim($_POST['description']); //Set am or pm for time $fStartTime = "$startTime $timeOfDay1"; $fEndTime = "$endTime $timeOfDay2"; //convert date to timestamp for storing in database $date = strtotime("{$_POST['year']}-{$_POST['month']}-{$_POST['day']}"); //Include files for conecting to database: $dbc = mysql_connect('rwddesign.com:3306', 'rwddesi1_bobby31', 'jessica'); mysql_select_db('rwddesi1_test'); //Define the query: $query = "INSERT INTO events (eventID, date, startTime, endTime, eventName, description) VALUES (0, '$date', '$fStartTime', '$fEndTime', '$eventName', '$description')"; //Exicute query if (@mysql_query($query)) { //Print message if secsessful print '<h1>Your event has been added!</h1>'; } else { //print message for all other errors. print '<h1 class="error">Could not add event because:' . mysql_error() . ' .</h1> <p class="error">The query being run was: ' . $query . '</p>'; include_once "$form"; } } } ?> </body> </html> Calendar <?php $date =time (); //Determans the time //Formate date $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); //Generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year); //Get month name $title = date('F', $first_day); //Find day of the week the first day falls on $day_of_week = date('D', $first_day); //Assign blank varable for blank days at beginnng of month 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; } //Find out how many days in month $days_in_month = cal_days_in_month(0, $month, $year); //Style the table echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Calendar</title> <style type=text/css> body { text-align: center; } h1 { color: #33f; } table { width: 500px; height: 500px; border-width: 6px; border-style: solid; border-color: #33f; margin-left: auto; margin-right: auto; } th, td { width: 62px; height: 62px; border-width: 1px; border-style: solid; border-color: #000000; text-align: center; } .today { background-color: #6cf; } .everyday, .today { text-align: left; vertical-align: text-top; } .weekday { height: 31px; color; #33f; } </style> </head>"; //Open body html tag echo"<body>"; //Create Table echo "<h1>$title $year</h1>"; echo "<table>"; echo "<tr><td class=\"weekday\">Sunday</td><td class=\"weekday\">Monday</td><td class=\"weekday\">Tuesday</td><td class=\"weekday\">Wedsday</td><td class=\"weekday\">Thursday</td><td class=\"weekday\">Friday</td><td class=\"weekday\">Saturday</td>"; //count days in week $day_count =1; //Echo table row echo "<tr>"; //Add blank days to beginning of calander while ( $blank > 0) { echo "<td> </td>"; $blank = $blank-1; $day_count++; } //Set day Number to 1 $day_num = 1; //count day of the month //increase day_num //increase day_count//Style current day while ( $day_num <= $days_in_month ) { if(date('d') !=$day_num) { echo "<td class=\"everyday\"> $day_num </td>"; $day_num++; $day_count++; } else { echo "<td class=\"today\">$day_num</td>"; $day_num++; $day_count++; } //create a new row if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Add blank days to end of calander while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } //Close table echo "</tr></table>"; //Close body tag echo "</body>"; ?> Quote Link to comment Share on other sites More sharing options...
bobby317 Posted June 16, 2010 Author Share Posted June 16, 2010 Still trying to figure this one out any ideas? Quote Link to comment Share on other sites More sharing options...
TOA Posted June 16, 2010 Share Posted June 16, 2010 That's alot of code. :-\ What is it that you're trying to do? What works and what doesn't? What have you tried so far? Quote Link to comment Share on other sites More sharing options...
bobby317 Posted June 16, 2010 Author Share Posted June 16, 2010 Ok sorry about that. First off all of the above code is in working fashion and is just there to show you how I am collecting and storing my data in the database I was not sure if it was needed. As for what I am trying to do the final application will be an event calendar. The part that I am on now is how to go about retrieving the events stored in my data base. I want my calendar the code for it is in my original post to place the event name into the correct date when building its self. I may have to remake the calendar but I am not sure. I am thinking I need to but the query into the second while statement and the echo it but I can't wrap my mind on how to do that. Thanks for any help you may be able to offer. Also please explain what you’re doing so I may learn. Quote Link to comment Share on other sites More sharing options...
TOA Posted June 16, 2010 Share Posted June 16, 2010 Your code looks pretty good. If you say it works I'll take your word for it. One thing I would say though, is that you need to read up on concatenation. What you need to do now is write a query that gets the event based on the day (so figure out how to do WHERE Date=$day_of_month or whatever variable it needs to be from your code) Then throw it into your echo. You know your code better than I do, what variable do you think you would use to determine what event to get? Quote Link to comment Share on other sites More sharing options...
TOA Posted June 16, 2010 Share Posted June 16, 2010 Ok, played around with your code for a while, and here's what I came up with. You'll need to tweak it a little, but this should get you going in the right direction while( $day_num <= $days_in_month ){ if(date('d') !=$day_num) { echo '<td class="everyday"><b>'.$day_num.'</b>'; $everyday_res = mysql_query("SELECT Field FROM Table WHERE Date_Avail='$year$month$day_num'", $con); while ($row_d = mysql_fetch_assoc($everyday_res)) { echo $row_d['Field']; } echo "</td>\r\n"; $day_num++; $day_count++; } else { echo '<td class="today"><b><i>'.$day_num.'</i></b>'; $today_res = mysql_query("SELECT Field FROM Table WHERE Date_Avail='$todays_date'", $con); while ($row_t = mysql_fetch_assoc($today_res)) { echo $row_t['Field']; } echo "</td>\r\n"; $day_num++; $day_count++; } //create a new row if ($day_count > 7){ echo "</tr><tr>\r\n"; $day_count = 1; } } Quote Link to comment Share on other sites More sharing options...
bobby317 Posted June 16, 2010 Author Share Posted June 16, 2010 Ok I have been working on this and I think I am getting really close to haveing it work. Here is my code as it stands now: <?php $date =time (); //Determans the time //Formate date $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); //Generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year); //Get month name $title = date('F', $first_day); //Find day of the week the first day falls on $day_of_week = date('D', $first_day); //Assign blank varable for blank days at beginnng of month 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; } //Find out how many days in month $days_in_month = cal_days_in_month(0, $month, $year); //Style the table echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Calendar</title> <style type=text/css> body { text-align: center; } h1 { color: #33f; } table { width: 500px; height: 500px; border-width: 6px; border-style: solid; border-color: #33f; margin-left: auto; margin-right: auto; } th, td { width: 62px; height: 62px; border-width: 1px; border-style: solid; border-color: #000000; text-align: center; } .today { background-color: #6cf; } .everyday, .today { text-align: left; vertical-align: text-top; } .weekday { height: 31px; color; #33f; } </style> </head>"; //Open body html tag echo"<body>"; //Create Table echo "<h1>$title $year</h1>"; echo "<table>"; echo "<tr><td class=\"weekday\">Sunday</td><td class=\"weekday\">Monday</td><td class=\"weekday\">Tuesday</td><td class=\"weekday\">Wedsday</td><td class=\"weekday\">Thursday</td><td class=\"weekday\">Friday</td><td class=\"weekday\">Saturday</td>"; //count days in week $day_count =1; //Echo table row echo "<tr>"; //Add blank days to beginning of calander while ( $blank > 0) { echo "<td> </td>"; $blank = $blank-1; $day_count++; } //Set day Number to 1 $day_num = 1; //count day of the month //increase day_num //increase day_count//Style current day while( $day_num <= $days_in_month ){ if(date('d') !=$day_num) { //connect to database $con = mysql_connect('rwddesign.com:3306', 'rwddesi1_bobby31', 'jessica'); mysql_select_db('rwddesi1_test'); echo '<td class="everyday\> $day_num'; $everday_res = mysql_query("SELECT field FROM events WHERE date='$year$month$day_num' LIMIT 0, 30", $con); while ($row_d = mysql_fetch_assoc($everyday_res, MYSQL_ASSOC)) { echo $row_d['Field']; } echo "</td>"; $day_num++; $day_count++; } else { echo '<td class="today">$day_num'; $today_res = mysql_query("SELECT Field FROM event WHERE date='$todays_date' LIMIT 0, 30", $con); while ($row_t = mysql_fetch_assoc($today_res, MYSQL_ASSOC)) { echo $row_t['Field']; } echo "</td>"; $day_num++; $day_count++; } //create a new row if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Add blank days to end of calander while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } //Close table echo "</tr></table>"; //Close body tag echo "</body>"; ?> When I go to the calendar i get this error: $day_num Warning: Wrong parameter count for mysql_fetch_assoc() in /home/rwddesi1/public_html/1stCalendar.php on line 120 Not sure were I am going wrong add thanks again for all your help. Quote Link to comment Share on other sites More sharing options...
TOA Posted June 17, 2010 Share Posted June 17, 2010 Ok, first of all...NEVER put your database info up on a forum...BAD, BAD, BAD I'm done *tisking* now I played with your original code and what I posted and got everything to work beautifully. In the query, I doubt your field name is "Field" so one issue might be that it needs to be the actual field your trying to select. And make sure the field name you're using in your WHERE is actually date (those were all just generic names to use in the example) Another thing I noticed are in these lines: [php $everday_res = mysql_query("SELECT field FROM events WHERE date='$year$month$day_num' LIMIT 0, 30", $con); $today_res = mysql_query("SELECT Field FROM event WHERE date='$todays_date' LIMIT 0, 30", $con);[/code] You have event and events And if those don't work, try combining $year$Month$day_num into its own variable, maybe your php doesn't like the way I used those variables there. Try those and let me know what happens. Quote Link to comment 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.