PHP - How Do I Mark Dates Php Modern-class-calendar Script
Hello, I found this great free php calandar script here "" by Xu and Alessandro, and I'm trying to modify the code to mark several dates(birthdays YYYY-mm-dd) from a date column in a sql database. I've played around with the _showDay() method but I can't seem to get it working.. I've also tried to create a _showBirthday() method to modify the css as well but with no luck. What I'm trying to do is loop through the database to mark the respective dates on the calendar, and have a href to display a new page with the person's name when I click the specific date. Can anyone help with this. Thanks in advance! Similar TutorialsThe junk I've found on phpclasses is well junk and not to mention really old. I started writing my own, but I frankly don't like the plumbing involved. Anyone have a great IMAP class? Something that just does the work for you? Hi all, I followed a tutorial to get the base of a php calendar done, then added some custom Javascript in order to be able to change the color of the cells. The calendar can be seen he http://www.education-world.co.uk/Education%20World%20Site/calendar.php The problem is now, that I need to integrate a SQL database to keep track of what was set for certain dates. I'm not sure of how to even begin this, all i need to do is keep track of if the candidate is available, not available or working for a specific day. The calendar is submitted to an email but this means when they return at a later date (availability may change) their previously set availability will have been wiped! I can provide code if needed. Can anyone help me out here, really struggling with this! Many thanks, Greens85 I have a simple php calendar script that works great however, I need to make the dates clickable referencing a db tables data. I tried changing the for loop to a while loop with no success so I am now trying to work with the for loop to make the dates (links); here is my complete script (using it as a calendar plugin) with comments to show my re-coding attempt. <?php $time = time(); $numDay = date('d', $time); $numMonth = date('m', $time); $strMonth = date('F', $time); $numYear = date('Y', $time); $firstDay = mktime(0,0,0,$numMonth,1,$numYear); $daysInMonth = cal_days_in_month(0, $numMonth, $numYear); $dayOfWeek = date('w', $firstDay); echo "<div class='row'>\n"; echo "<table width='100%' border='0'><tr>\n"; echo "<td align='center'><span style='font-size:16px; color:#FCF9B6;'><b>Calendar</b></span><p>\n"; echo "<table width='63%' border='1' cellpadding='5'><tr>\n"; echo "<td bgcolor='#AFAFAF'><table width='100%' cellpadding='4' border='1'>\n"; echo "<caption style='text-align:center; font-size:16px; background:#B83C32; color:#fff;'><b>$strMonth $numYear</b></caption>\n"; echo "<thead><tr>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Sunday' scope='col' title='Sunday'>S</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Monday' scope='col' title='Monday'>M</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Tuesday' scope='col' title='Tuesday'>T</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Wednesday' scope='col' title='Wednesday'>W</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Thursday' scope='col' title='Thursday'>T</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Friday' scope='col' title='Friday'>F</th>\n"; echo "<th style='text-align:center; font-size:12px;' bgcolor='#005500' abbr='Saturday' scope='col' title='Saturday'>S</th>\n"; echo "</tr></thead><tbody><tr>\n"; if($dayOfWeek !=0) { echo "<td style='text-align:center; font-size:12px; color:#000; background:#ddd;' colspan='".$dayOfWeek."'></td>\n"; } for($i=1;$i<=$daysInMonth;$i++) { /* my inserted coding for db query */ $moz = date('n', $time); $result = dbquery("SELECT * From ".DB_GRIMS_BLOG_POST_TOPIC." WHERE art_mon='$moz'"); if (dbrows($result)) { while($data = dbarray($result)) { $dah = $data['art_day']; $pst = $data['post_id']; } if($i == $dah) { "<a href='../grims_blog/filtered.php?post_id=$pst'>$i</a>"; } /* normal script continues */ if($i == $numDay) { echo "<td style='text-align:center; font-size:12px; color:#fff; background:#890000;'><b>\n"; } else { echo "<td style='text-align:center; font-size:12px; color:#000; background:#ddd'><b>\n"; } $padding = $i; $padding = str_pad($padding, 2, '0', STR_PAD_LEFT); echo $padding; echo "</b></td>\n"; /* closing of db query inserted here */ } /* ends here */ if(date('w', mktime(0,0,0,$numMonth, $i, $numYear)) == 6) { echo "</tr>\n"; } } echo "</tbody>\n"; echo "</table></td></tr></table>\n"; echo "</td></tr></table><br /><br /></div>\n"; ?> It doesn't throw an error but it doesn't work either. Any help would be appreciated. I have a mysql database where users enter their data using a form that includes a rundate input field that generates a calendar date in this type of format: xx/xx/xxxx into a mysql database field called rundate. I would like to query the database to search a string of dates that are in the database, such as 01/01/2011, 01/02/2011, 01/03/2011 but I'm not sure on how to code this into my search.php. I have attached the search page to this post. Any suggestions would be greatly appreciate, and if you need me to be more expanded on my explanation, just let me know....i try to keep it very simplistic. [attachment deleted by admin] Hi, I want to check entered dates and times that a user selects against my "book-off" calendar which is a Google Calendar. The dates× from Google is in the form: 2011-04-29T23:00:00.000+02:00 The dates in my booking software (ABPro) is in the form: 2011-04-29 Times in form: 23:00:00 All I want the function to return is a number other than 0 if any of the dates/times in Google feed overlap the requested date/time entered in the booking. So I add a function and get the feed from Google: Code: [Select] function checkOverlapG($calendarID, $startdate, $starttime, $enddate, $endtime){ // Create an instance of the Calendar service using an unauthenticated //HTTP client $service = new Zend_Gdata_Calendar(); //Retrieving events in order of start time $query = $service->newEventQuery(); $query->setUser('calendarID'); // Set to $query->setVisibility('private-magicCookieValue') if using MagicCookie auth $query->setVisibility('public'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortOrder('ascending'); //start with first event in future //seFutureevents must be commented out when using start and end times. $query->setFutureevents('true'); $query->setSingleEvents('true'); $query->setMaxResults('200'); //Guess this could be anything, but can possibly make things slower. Default 25 events //$query->setStartMin('2006-12-01'); //$query->setStartMax('2006-12-16); // setStartMax is exclusive, will not include last date. Must add +1 day. // Retrieve the event list from the calendar server try { $eventFeed = $service->getCalendarEventFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); return null; } Now I want to compare the dates and times and see if any of them collide or overlap. I want to add a counter, and if any of the events overlap, I want the counter to add one number. 1. the first thing I do is check if the event feed include. any events. 2. then I add a counter 3. then I run a foreach to retrieve events one at a time 4. then I change the date and time format from Google Event to match the date and time format form the booking. 5. If fullday event from google, no time information is added, so I add this 6. COMPARE DATES AND TIMES and if overlapping events --> n++; I've not gotten this code to work. Probably I'm doing something wrong, and I'm sorry but I'm completely new to this. Getting the Google Calendar data is working fine, and so is changing the format of the dates/times to be same format as request data. After that (and before, I don't know). Code: [Select] $gCount = count($eventFeed); $n = 0; if (gCount>0){ foreach($eventFeed as $event){ foreach ($event->when as $when) { //Getting rid of extra 00's and time zone info for now $startGevent = $when->startTime; $startGevent = str_replace('.000+02:00',"",$startGevent); $endGevent = $when->endTime; $endGevent = str_replace('.000+02:00',"",$endGevent); //Splitting date and time into two variables list($startDateEvent, $startTimeEvent) = split('T',$startGevent); list($endDateEvent, $endTimeEvent) = split('T',$endGevent); //Fill in the blanks if($startTimeEvent!=0) {} else{$startTimeEvent = "00:00:00";} if($endTimeEvent!=0) {} else{$endTimeEvent = "00:00:00";} //Compare dates if($startdate == $endDateEvent){ if($starttime > $endTimeEvent OR $endtime < $startTimeEvent){} else { n++; } } if($enddate == $startDateEvent){ if($endtime < $startTimeEvent OR $starttime > $endTimeEvent){} else { n++; } } } } return $n; } Attempting to set a variable = NOW() + INTERVAL 90 DAY; I can run SELECT DATE_ADD(NOW(), INTERVAL 90 DAY using MYSQL, but don't know how to move result to a variable. Anyone have info on a simple PHP script that can display a particular month where you can insert events such as a birthday or special event? Not looking for anything too complicated or fansy. thanks Hello. I'm trying to build a site where users can book appointments with personal trainers. I want to use the free and open source jQuery Full Calendar for the look and feel of the calendar since it looks pleasant and is responsive. <link removed> I want each personal trainer to have their own calendar which will show the days that they're available. When a user clicks on an available day then they will see a list of time slots that they can book in 15 minute increments. So, for instance lets say a trainer named Mike is available on Mondays-Friday from 8am-5pm. If a user comes to his calendar they will see that certain days are not fully booked and they can click on a day. Then when they click on a day they can see time intervals like this: Mike's available time slots for Tuesday August 25, 2014: 8:00 am-9:00 am - Click here to book appointment! 8:15 am-9:15 am - Click here to book appointment! 2:00 pm - 3:00 pm - Click here to book appointment! The page above can be a separate page from the calendar, but it would need to be synced with the calendar to be able to fetch the times and days that he's available for appointments. Then when the user clicks on a day, he can book an appointment and after the trainer confirms via email then the user will receive an email confirmation that his appointment is scheduled. While it's still being confirmed though, that time slot would need to be no longer visible to other users, so that there wouldn't be multiple bookings for the same time slot, to avoid those conflicts. So, the application would need to fetch the data from MySQL and use that to display the available days. If a day is not available then the user will not be able to click on it in the calendar. Also, the trainers should be able to set their schedule which will get updated to MySQL, so the schedule is normally recurring but they should also be able to change certain days if they feel like they can or cannot work on that day. Also, the appointments will vary by time, so a training session can last 30 minutes, 1 hour, 3 hours, 1 hour and a half, etc. and that would need to be taken into account when the user books an appointment because if the trainer has a 1 hour gap between 2pm and 3pm, but the session is for 2 hours, they should not be able to book that time slot, since it wouldn't make any sense. What makes this complicated is that the appointment lengths can vary. Otherwise, if every appointment was 1 hour long I would be able to just create a table for appointment times and do a query to see if they're booked and only show the booked ones. How can I do it with variable time lengths? Any help would be greatly appreciated. Edited by mac_gyver, 16 August 2014 - 09:04 AM. removed link, not relevant to post Hey guys,
Ive been working on this script and I cant seem to figure out how to highlite the current date in lets say a blue color.
Any ideas please?
<!DOCTYPE html> <html> <head> <title>Simple Month Calendar</title> <script type="text/javascript"> // Author: Danny van der ven // Created: 12 aug 2014 // P.S. I'm from The Netherlands, so the names of the weeks and months are in Dutch. var Calendar = function(divId) { //Store div id this.divId = divId; // Days of week, starting on Sunday this.DaysOfWeek = [ 'Z', 'M', 'D', 'W', 'D', 'V', 'Z' ]; // Months, stating on January this.Months = ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december' ]; // Set the current month, year var d = new Date(); this.CurrentMonth = d.getMonth(); this.CurrentYear = d.getFullYear(); }; // Goes to next month Calendar.prototype.nextMonth = function() { if ( this.CurrentMonth == 11 ) { this.CurrentMonth = 0; this.CurrentYear = this.CurrentYear + 1; } else { this.CurrentMonth = this.CurrentMonth + 1; } this.showCurrent(); }; // Goes to previous month Calendar.prototype.previousMonth = function() { if ( this.CurrentMonth == 0 ) { this.CurrentMonth = 11; this.CurrentYear = this.CurrentYear - 1; } else { this.CurrentMonth = this.CurrentMonth - 1; } this.showCurrent(); }; // Show current month Calendar.prototype.showCurrent = function() { this.showMonth(this.CurrentYear, this.CurrentMonth); }; // Show month (year, month) Calendar.prototype.showMonth = function(y, m) { var d = new Date() // First day of the week in the selected month , firstDayOfMonth = new Date(y, m, 1).getDay() // Last day of the selected month , lastDateOfMonth = new Date(y, m+1, 0).getDate() // Last day of the previous month , lastDayOfLastMonth = m == 0 ? new Date(y-1, 11, 0).getDate() : new Date(y, m, 0).getDate(); var html = '<table>'; // Write selected month and year html += '<tr><td colspan="7">' + this.Months[m] + ' - ' + y + '</td></tr>'; // Write the header of the days of the week html += '<tr>'; for(var i=0; i < this.DaysOfWeek.length;i++) { html += '<td>' + this.DaysOfWeek[i] + '</td>'; } html += '</tr>'; // Write the days var i=1; do { var dow = new Date(y, m, i).getDay(); // If Sunday, start new row if ( dow == 0 ) { html += '<tr>'; } // If not Sunday but first day of the month // it will write the last days from the previous month else if ( i == 1 ) { html += '<tr>'; var k = lastDayOfLastMonth - firstDayOfMonth+1; for(var j=0; j < firstDayOfMonth; j++) { html += '<td class="not-current">' + k + '</td>'; k++; } } // Write the current day in the loop html += '<td>' + i + '</td>'; // If Saturday, closes the row if ( dow == 6 ) { html += '</tr>'; } // If not Saturday, but last day of the selected month // it will write the next few days from the next month else if ( i == lastDateOfMonth ) { var k=1; for(dow; dow < 6; dow++) { html += '<td class="not-current">' + k + '</td>'; k++; } } i++; }while(i <= lastDateOfMonth); // Closes table html += '</table>'; // Write HTML to the div document.getElementById(this.divId).innerHTML = html; }; // On Load of the window window.onload = function() { // Start calendar var c = new Calendar("divCalendar"); c.showCurrent(); // Bind next and previous button clicks getId('btnNext').onclick = function() { c.nextMonth(); }; getId('btnPrev').onclick = function() { c.previousMonth(); }; } // Get element by id function getId(id) { return document.getElementById(id); } </script> <style type="text/css"> td.not-current { color: #777; } </style> </head> <body> <div id="divCalendar"> </div> <button id="btnPrev" type="button">Terug</button> <button id="btnNext" type="button">Vooruit</button> </body> </html> Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314342.0 Is this an acceptable way to instantiate classes?
//$_SESSION['product'] = {'ProductA', 'ProductB', ... 'ProductX'} $p = new $_SESSION['product'](); $p->save();I am usually used to calling out classes explicitly where class name is not a variable but a hardcoded string. Sometimes I use if/then/else in order to do this. Here it is a variable and it bothers me a little bit. But PHP allows me to do this. Is this an acceptable latest & gratest modern PHP object oriented web technology technique or not ? Im trying to rermove ' symbol from a string. Code: [Select] $string2 = str_replace(" ' ", " . ", $string1); give errors How else could i do this? Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. Thanks I made a template class recently and the only problem I'm having with it is that when I pull the HTML through if I add double quotes anywhere it breaks the code. I understand why its breaking sorta but I can't figure out how to fix it. Code: (HTML) [Select] <html> <head> </head> <body> <p id='Element'>"Something in quotes"</p> </body> </html> Code: (PHP) [Select] $string = $template->myMethod();//Returns the html in a string eval("\$HTML = \"$string\";"); //The error happens during the evaluation here echo($HTML); The string breaks with double quotes during the eval method and I've tried replacing the " mark with \" by using str_replace but i haven't been able to get it to work. Thanks for your replies I imagine there are lots of ways to answer this question, so I just want people's opinions as to the best way (if there is one). I have code with a basic form that submits data to a MySQL database. So when someone submits data the first time, I "clean it up" by doing... Code: [Select] $_POST['data'] = trim(mysql_prep($_POST['data'])); .. and then submit that info into a "varchar" mySQL field. Then if the user comes back to edit it, the form comes up and the data they previously entered is pulled into the field this way (I'm leaving out the MySQL to pull the data, obviously)... Code: [Select] <input type="text" name="field" value="<?php echo $data;?>"> The problem is that if someone entered this originally... Code: [Select] Here is "some" data with apostrophes ...Then when I echo that back into the value of the text field, it would only show... Code: [Select] Here is "...and then cuts off because the quotation mark in the data conflicted with the quotation mark after value= Is htmlentities the answer here, or is there some other/better way? FYI... Code: [Select] function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string") ; //i.e. PHP >= v4.3.0 if($new_enough_php) { //PHP v4.3.0 or higher //undo any magic quote effects so mysql_real_escape_string can do the work if($magic_quotes_active) { $value = stripslashes($value) ;} $value = mysql_real_escape_string($value); } else { //before php v4.3.0 // if magic quotes aren;t already on then add slashes manually if(!magic_quotes_active) { $value = addslashes($value); } // if magic quotes are active, then the slashes already exist } return $value; } So I really don't think I need to paste the code but Code: [Select] <?php session_start(); ?> <?php $new_thread_page_path = 'general_discussion_threads/' . $_POST['thread_title'] . '.php'; $new_table_link = '<a href="' . $new_thread_page_path . '"' . 'class="hover" border="0" style="text-decoration:none">' . $_POST['thread_title'] . '</a>'; ?> <?php date_default_timezone_set('EST'); $date = date("m/d/y"); $hour = date("g"); $minute = date("i"); $second = date("s"); $am_pm = date("a"); $full_date = $date . ' ' . $hour . ":" . $minute . ":" . $second . $am_pm; $place_holder = '<!--the_place_holder-->'; $current_page_path = 'general_discussion_home.php'; $open_current_page = fopen($current_page_path, 'rb'); $contents_of_current_page = fread($open_current_page, filesize($current_page_path)); $template_path = 'general_discussion_threads/template.php'; $open_template = fopen($template_path, 'rb'); $template_contents = fread($open_template, filesize($template_path)); $new_thread_page_path = 'general_discussion_threads/' . $_POST['thread_title'] . '.php'; $list_file_path = 'general_discussion_threads/thread_list.txt'; $list_open = fopen($list_file_path, 'rb'); $list_open_write = fopen($list_file_path, 'a'); $open_new_thread_page = fopen($new_thread_page_path, 'w+'); $list_contents = fread($list_open, filesize($list_file_path)); $thread_exists_test = substr_count($list_contents, '<' . strtolower($_POST['thread_title'] . '>')); $invalid_character_test = substr_count($_POST['thread_title'], '<'); $invalid_character_test1 = substr_count($_POST['thread_title'], '>'); $the_users_info = $_SESSION['the_user']; $the_username1 = strstr($_SESSION['the_user'], '.'); $the_username1_wipe = str_replace($the_username1, '', $the_users_info); $the_username = str_replace('.', '', $the_username1_wipe); if (isset($_POST['new_thread_post'])) { if (($_SESSION['logged_in'] == '1') && ($invalid_character_test1 == '0') && ($invalid_character_test == '0') && ($thread_exists_test == '0') && ($_POST['thread_title'] != '') && ($_POST['thread_title'] != 'Enter the title of your Thread...')) { fwrite($open_new_thread_page, '<?php $the_thread_title = ' . '\'' . $_POST['thread_title'] . '\'' . '; ?>' . $template_contents); fclose($open_new_thread_page); fwrite($list_open_write, '<' . strtolower($_POST['thread_title']) . '>'); fclose($list_open_write); $new_contents =str_replace($place_holder, '<tr><td align="center">' . $new_table_link . '</td>' . '<td align="center">' . '<font color="#66CC00">' . $full_date . '</font>' . '</td>' . '<td align="center">' . '<font color="#66CC00">' . $the_username . '<font>' . '</td>' . '</tr>' . $place_holder, $contents_of_current_page); $open_current_page = fopen($current_page_path, 'w'); fwrite($open_current_page, $new_contents); fclose($open_current_page); $_SESSION['gd_error'] = 'Thread created succesfully!'; } elseif ($_SESSION['logged_in'] != '1') { $_SESSION['gd_error'] = 'You need to be logged in!'; } elseif ($invalid_character_test != '0') { $_SESSION['gd_error'] = 'Thread title contains invalid characters!'; } elseif ($invalid_character_test1 != '0') { $_SESSION['gd_error'] = 'Thread title contains invalid characters!'; } elseif ($thread_exists_test != '0') { $_SESSION['gd_error'] = 'Thread title unavailable!'; } elseif ($_POST['thread_title'] == '') { $_SESSION['gd_error'] = 'You must make a thread title!'; } elseif ($_POST['thread_title'] == 'Enter the title of your Thread...') { $_SESSION['gd_error'] = 'You must make a thread title!'; } } ?> So what all this does is based on user input it creates a new html page based off of the template with a few different variables based on input. Then it makes a new row and 3 cells in the home pages thread table that link to the page say who made it and what time they made it. Now it all works PERFECT (Im suprised how perfect on the first try actually) except for 1 tiny flaw which i think might be php not me but im not sure. The fwrite creates a new file but if the input contains any question marks (?) the link will work but no file will be created. For everyother character on teh standard keyboard its fine but not the question mark. What gives? thanks yall! MOD EDIT: <code></code> tags changed to proper [code] . . . [/code] BBCode tags. Hello, I am using a tutorial script for generating a basic bar graph. I have attempted to convert this script into an object-oriented script. However, upon attempting to define the graph, it is not successfully generated. Here is my code: Code: [Select] <? class Graph { var $values; var $image; var $image_width = 450; var $image_height = 300; var $margin = 20; var $bar_size = 20; var $horizontal_lines = 20; var $bar_colour; var $border_colour; var $background_colour; var $line_colour; function CreateGraph() { $this->image = imagecreate($this->image_width, $this->image_height); } function SetSize($width, $height) { $this->image_width = $width; $this->image_height = $height; } function SetMargin($size) { $this->margin = $size; } function SetBarSize($size) { $this->bar_size = $size; } function SetHorLines($size) { $this->horizontal_lines = $size; } function HexConvert($rgb) { return array( base_convert(substr($rgb, 0, 2), 16, 10), base_convert(substr($rgb, 2, 2), 16, 10), base_convert(substr($rgb, 4, 2), 16, 10), ); } function SetColours($bars, $background, $border, $line) { // This is hex based, similar to CSS, it is converted by HexConvert $bars = $this->HexConvert($bars); $background= $this->HexConvert($background); $border= $this->HexConvert($border); $line = $this->HexConvert($line); $this->bar_colour = imagecolorallocate($this->image, $bars[0], $bars[1], $bars[2]); $this->background_colour = imagecolorallocate($this->image, $background[0], $background[1], $background[2]); $this->border_colour = imagecolorallocate($this->image, $border[0], $border[1], $border[2]); $this->line_colour =imagecolorallocate($this->image, $line [0], $line [1], $line [2]); } function DrawBorders() { imagefilledrectangle($this->image,1,1,$this->image_width-2,$this->image_height-2,$this->border_colour); imagefilledrectangle($this->image,$this->margin,$this->margin,$this->image_width-1-$this->margin,$this->image_height-1-$this->margin,$this->background_colour); } function DrawHorLines($horizontal_gap, $ratio) { for($i=1;$i<=$this->horizontal_lines;$i++) { $y = $this->image_height - $this->margin - $horizontal_gap * $i ; imageline($this->image, $this->margin, $y, $this->image_width - $this->margin, $y, $this->line_colour); $v = intval($horizontal_gap * $i / $ratio); imagestring($this->image, 0, 5, $y-5, $v, $this->bar_colour); } } function DrawBars($graph_height, $gap, $ratio) { for($i=0;$i< $total_bars; $i++) { list($key,$value)=each($this->values); $x1= $this->margin + $gap + $i * ($gap+$this->bar_size) ; $x2= $x1 + $this->bar_size; $y1 = $this->margin +$graph_height- intval($value * $ratio) ; $y2 = $this->image_height-$this->margin; imagestring($this->image,0,$x1+3,$y1-10,$value,$this->bar_colour); imagestring($this->image,0,$x1+3,$this->image_height-15,$key,$this->bar_colour); imagefilledrectangle($this->image,$x1,$y1,$x2,$y2,$this->bar_colour); } } function DrawGraph() { $graph_width=$this->image_width - $this->margin * 2; $graph_height=$this->image_height - $this->margin * 2; $total_bars = count($values); $gap = ($graph_width- $total_bars * $this->bar_width ) / ($total_bars +1); $this->DrawBorders(); $max_value=max($values); $ratio = $graph_height / $max_value; $horizontal_gap = $graph_height / $horizontal_lines; $this->DrawHorLines($horizontal_gap, $ratio); $this->DrawBars($graph_height, $gap, $ratio); } function OutputGraph() { header("Content-type:image/png"); imagepng($this->image); } } ?> I expect this to be my misunderstanding of how object orientated codes work. I'm also open to any suggestions for improvement. Edit: Here is the script where I use the class. Code: [Select] <? include "bargraph.class.php"; $graph = new Graph; $graph->SetSize(450, 300); $graph->CreateGraph(); $graph->SetMargin(20); $graph->SetBarSize(20); $graph->SetHorLines(20); $graph->SetColours("FFFFFF", "C0C0C0", "000000", "000000"); $graph->DrawGraph(); $graph->OutputGraph(); ?> I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); I have mysqli object in Database class base: [color=]database class:[/color] class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); [color=]Error that go out is follow[/color] Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change Please help me |