Jump to content

Got great help here, but having trouble implementing?


Izzy-B

Recommended Posts

I registered a few days ago for help on this thread but didn't post again on it now because it has been marked answered and I thought I'd better not bump it.  I received help in a way that has been the most encouraging since I began my calendar project.  I'm wondering, though, if you would help me understand why I'm not successful at implementing the advice to the point that events are inserting into my calendar. 

 

My testing database has only one table:  events and in events, only two columns (other than id):  "startdt" and "description".  This is a screenshot of how the table's columns are set upL

 

post-172546-0-97920800-1408147427_thumb.jpg

 

This is a screenshot of the table content:

 

post-172546-0-96768100-1408147632_thumb.jpg

 

This is my code with the edits added from the support thread:

<?PHP

$var = mysql_real_escape_string($_GET['startdt, description']);

$con=mysql_connect("localhost","user","password");
// Check connection
if (mysql_connect_error()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
    //select a database to work with
    $selected = mysql_select_db("mydatabase_",$con) 
      or die("Could not select mydatabase_");

    //execute the SQL query and return records
    $result = mysql_query("SELECT information FROM events WHERE value='$startdt', 'description'");
    //fetch tha data from the database
    while ($row = mysql_fetch_array($result)) {
       echo $row{'startdt, description'};
    }

    //close the connection
    mysql_close($con);

?>

<!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" />
<link rel="stylesheet" href="css/master.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html" />
<title>Yet Another Test</title>
</head>
<body>
<?php
    $currMonth = isset($_GET['month']) ? $_GET['month']  : date('n');
    $currYear  = isset($_GET['year'])  ? $_GET['year']   : date('Y');
    $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;

    $prevMonth = $currMonth==1 ? 12 : $currMonth-1;
    $nextMonth = $currMonth==12?  1 : $currMonth+1;
    $prevYear = $currMonth==1 ? $currYear-1 : $currYear;
    $nextYear = $currMonth==12? $currYear+1 : $currYear;

    $day1 = mktime(0,0,0,$currMonth,1,$currYear);
    $dim = date('t', $day1);
    $dayN = mktime(0,0,0,$currMonth,$dim,$currYear);
    $dow1 = (date('w',$day1)+0) % 7;
    $dowN = (date('w',$dayN)+0) % 7;
    $calHead = date('F Y',$day1);
    	echo <<<EOT
    	<div class="calwrapper">
    	<div class="caltitle"><h1>Calendar</h1></div>
    	<div class="container">
    	<div class="fnl first"></div>
    	<div class="adjust"></div>
    	<div class="fnl last"></div>
    	</div>
    	<div class="caldisplay">
        <table cellspacing="0">
        <tr>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
        <td colspan="5" class="adjust">$calHead</td>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
        </tr>
        <tr>
          <th class="we">Sun</th>
          <th class="wd">Mon</th>
          <th class="wd">Tue</th>
          <th class="wd">Wed</th>
          <th class="wd">Thu</th>
          <th class="wd">Fri</th>
          <th class="we">Sat</th>
         </tr>
        <tr>
EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
        if ($c%7==0) echo "</tr><tr>";
        $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
        $st = ($d == $today) ? "style='padding: 0px;'" : '';
        echo "<td class=\"$cl\" $st>\n";
        echo "$d" ;
        echo "</td>\n";
    }
    while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>';
    echo "</tr></table>\n";
    echo '</div></div>';
    
// calander entries. Use the date as the key (in YYYY/MM/DD format)
$entries = array(
	'2014/8/16' => array(
        				'Event',
					),
	
);
    for ($d=1; $d<=$dim; $d++, $c++) {

        if ($c%7==0) echo "</tr><tr>";

        $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';

        $st = ($d == $today) ? "style='padding: 0px;'" : '';

        echo "<td class=\"$cl\" $st>\n";

        echo "$d" ;

        echo "</td>\n";

    }

// construct the date, this will be used to check to if the key exists in the $entries array
        $dateKey = "$currYear/$currMonth/$d";
        // check if the key exists in the $entries array
        if(array_key_exists($dateKey, $entries)) {
            // for each event, list it in a seperate tool tip
            foreach($entries[$dateKey] as $entry) {
                echo '<div class="has-tooltip">
           Event
            <span class="tooltip">'.$entry.'</span>
        </div>';
            }
        }    
    
?>
</body>
</html>

I am not getting any errors in the PHP Code Checker (although I am receiving the notice that these functions are now deprecated):

  • mysql_close()
  • mysql_connect()
  • mysql_fetch_array()
  • mysql_query()
  • mysql_real_escape_string()
  • mysql_select_db()

When I upload my page to the server, everything seems fine, except that no information is added to the table.  When I check the page source, I see this:

 <!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" />
<link rel="stylesheet" href="css/master.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html" />
<title>Yet Another Test</title>
</head>
<body>
    	<div class="calwrapper">
    	<div class="caltitle"><h1>Calendar</h1></div>
    	<div class="container">
    	<div class="fnl first"></div>
    	<div class="adjust"></div>
    	 <div class="fnl last"></div>
    	 </div>
    	 <div class="caldisplay">
        <table cellspacing="0">
        <tr>
          <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=7"> Prev </a></td>
          <td colspan="5" class="adjust">August 2014</td>
          <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=9"> Next </a></td>
        </tr>
        <tr>
          <th class="we">Sun</th>
          <th class="wd">Mon</th>
          <th class="wd">Tue</th>
          <th class="wd">Wed</th>
          <th class="wd">Thu</th>
          <th class="wd">Fri</th>
          <th class="we">Sat</th>
         </tr>
        <tr><!--DEBUG: year=$currYear and month=$currMonth<hr/--><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="we" >
1</td>
<td class="we" >
2</td>
</tr><tr><td class="wd" >
3</td>
<td class="wd" >
4</td>
<td class="wd" >
5</td>
<td class="wd" >
6</td>
<td class="wd" >
7</td>
<td class="we" >
8</td>
<td class="we" >
9</td>
</tr><tr><td class="wd" >
10</td>
<td class="wd" >
11</td>
<td class="wd" >
12</td>
<td class="wd" >
13</td>
<td class="wd" >
14</td>
<td class="we" style='padding: 0px;'>
15</td>
<td class="we" >
16</td>
</tr><tr><td class="wd" >
17</td>
<td class="wd" >
18</td>
<td class="wd" >
19</td>
<td class="wd" >
20</td>
<td class="wd" >
21</td>
<td class="we" >
22</td>
<td class="we" >
23</td>
</tr><tr><td class="wd" >
24</td>
<td class="wd" >
25</td>
<td class="wd" >
26</td>
<td class="wd" >
27</td>
<td class="wd" >
28</td>
<td class="we" >
29</td>
<td class="we" >
30</td>
</tr><tr><td class="wd" >
31</td>
<td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td></tr></table>
</div></div></body>
</html>

I don't have an understanding of what the Debug is telling me although I note the number "1" within the tag and find that interesting because on those occasions, earlier today, when the file upload would result in a white page, viewing the page source would reveal nothing but the numeral "1" in the upper left top.

 

Are the deprecated functions enough to cause the event not to insert into the calendar?  I'd appreciate any help in sorting why I'm not succeeding.  As you see so often around here, I'm not a coder.  I'm just forced into a position to have to fend for myself, as of late, and so I'm trying to learn what I can.  Thank you for any help.  :)

Link to comment
Share on other sites

Hi Izzy.

 

I don't want to sound like a wet blanket, especially since this isn't actually addressing your question, but at this point we really have to insist that EVERYONE needs to convert their mysql_ code to either mysqli_ or PDO/Mysql. The entire mysql_ library is deprecated and will be removed entirely from php in the near future.

 

There is no point in us helping you debug code that is already obsolete when you write it. You should be using either mysqli or PDO, and with bind variables it is a game changer in terms of escaping (you don't need to) and the elimination of SQL injection exploits.

 

Also FWIW, I don't see anyplace where you are doing a SQL INSERT or implementing a form, so I'm not sure what you mean by "nothing added".

Link to comment
Share on other sites

Hi Izzy.

 

I don't want to sound like a wet blanket, especially since this isn't actually addressing your question, but at this point we really have to insist that EVERYONE needs to convert their mysql_ code to either mysqli_ or PDO/Mysql. The entire mysql_ library is deprecated and will be removed entirely from php in the near future.

 

There is no point in us helping you debug code that is already obsolete when you write it. You should be using either mysqli or PDO, and with bind variables it is a game changer in terms of escaping (you don't need to) and the elimination of SQL injection exploits.

 

Also FWIW, I don't see anyplace where you are doing a SQL INSERT or implementing a form, so I'm not sure what you mean by "nothing added".

 

Oh, I'm sorry.  I just learned this week that certain functions are becoming (have become) deprecated and I suppose the task at hand now is to learn how to accommodate the changes.  (I should follow the mantra I've seen on various support forums the past few days and "RTFM".)  :)

 

I'll spend this day doing that and try to grasp how to edit my code to reflect the changes in function mark up.

 

Here is a prime example of my complete lack of understanding:  Your observation about not seeing where I am doing  a SQL INSERT or implementing a form.  I did begin entering information into other test databases that way but then found that I could use PhPMYAdmin to populate my rows and, since I am the only one who would be entering information, believed that this would be sufficient.  This is why I did not include an INSERT in my file. Clearly, I do not understand the INSERT statement, if this is why events are not being displayed on my calendar.  I just assumed that once the actual data was inserted into my rows via PhPMYAdmin, this was all that was needed and that I only now needed to query and fetch the data. 

 

As I mentioned before, personal circumstances force me to suddenly have to fend for myself, where my web site is concerned and I've only been at this for a week.  I can score an entire musical on the back of a napkin while pretending to listen to my dinner companions  but I can't seem to wrangle PHP. 

 

I'll apply myself to understanding how to edit the now-deprecated functions.  Would anyone please explain to me how I'm misunderstanding INSERT and why it's still needed within the file, even though I've manually populated the row via PhPMYAdmin?  I'd so appreciated being educated, especially if this is why my calendar is not working as it should.

 

Thank you for your patience. 

Link to comment
Share on other sites

I seem to have run out of time to come back and edit my previous reply so please know that there is a reply before this one.  :)

 

I hope I have edited the file correctly to reflect the changes in deprecated functions? 

 <?PHP
$conn=($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost",  "user",  "password", "database_", "3306")) or die ('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

$port = ini_get("mysql.default_port");
echo "the port ". $port;

    //execute the SQL query and return records
    $result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT information FROM events WHERE value='$startdt', 'description'");
    //fetch tha data from the database
    while ($row = mysqli_fetch_array($result)) {
       echo $row{'startdt, description'};
    }

    //close the connection
    ((is_null($___mysqli_res = mysqli_close($con))) ? false : $___mysqli_res);

?> 
  

<!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" />
<link rel="stylesheet" href="css/master.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html" />
<title>Yet Another Test</title>
</head>
<body>
<?php
    $currMonth = isset($_GET['month']) ? $_GET['month']  : date('n');
    $currYear  = isset($_GET['year'])  ? $_GET['year']   : date('Y');
    $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;

    $prevMonth = $currMonth==1 ? 12 : $currMonth-1;
    $nextMonth = $currMonth==12?  1 : $currMonth+1;
    $prevYear = $currMonth==1 ? $currYear-1 : $currYear;
    $nextYear = $currMonth==12? $currYear+1 : $currYear;

    $day1 = mktime(0,0,0,$currMonth,1,$currYear);
    $dim = date('t', $day1);
    $dayN = mktime(0,0,0,$currMonth,$dim,$currYear);
    $dow1 = (date('w',$day1)+0) % 7;
    $dowN = (date('w',$dayN)+0) % 7;
    $calHead = date('F Y',$day1);
    	echo <<<EOT
    	<div class="calwrapper">
    	<div class="caltitle"><h1>Calendar</h1></div>
    	<div class="container">
    	<div class="fnl first"></div>
    	<div class="adjust"></div>
    	<div class="fnl last"></div>
    	</div>
    	<div class="caldisplay">
        <table cellspacing="0">
        <tr>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
        <td colspan="5" class="adjust">$calHead</td>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
        </tr>
        <tr>
          <th class="we">Sun</th>
          <th class="wd">Mon</th>
          <th class="wd">Tue</th>
          <th class="wd">Wed</th>
          <th class="wd">Thu</th>
          <th class="wd">Fri</th>
          <th class="we">Sat</th>
         </tr>
        <tr>
EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
        if ($c%7==0) echo "</tr><tr>";
        $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
        $st = ($d == $today) ? "style='padding: 0px;'" : '';
        echo "<td class=\"$cl\" $st>\n";
        echo "$d" ;
        echo "</td>\n";
    }
    while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>';
    echo "</tr></table>\n";
    echo '</div></div>';
    
// calander entries. Use the date as the key (in YYYY/MM/DD format)
$entries = array(
	'2014/8/16' => array(
        				'EVENT',
					),
);
    for ($d=1; $d<=$dim; $d++, $c++) {

        if ($c%7==0) echo "</tr><tr>";

        $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';

        $st = ($d == $today) ? "style='padding: 0px;'" : '';

        echo "<td class=\"$cl\" $st>\n";

        echo "$d" ;

        echo "</td>\n";

    }

// construct the date, this will be used to check to if the key exists in the $entries array
        $dateKey = "$currYear/$currMonth/$d";
        // check if the key exists in the $entries array
        if(array_key_exists($dateKey, $entries)) {
            // for each event, list it in a seperate tool tip
            foreach($entries[$dateKey] as $entry) {
                echo '<div class="has-tooltip">
           Event
            <span class="tooltip">'.$entry.'</span>
        </div>';
            }
        }    
    
?>
</body>
</html>

 I am able to connect to the database but when I load the page, the numbers 1 through 31 now appear below my calendar.  HERE IS THE TEST PAGE.

 

 

HA, and the words "the port"!  Screwed that up!  I'll try to clean that up.  :)

 

P.S. (I did clean up "the port" appearing at the top of my file, if anyone's already checked the page and seen it there before.  I didn't actually need that; I can connect without it.)

Link to comment
Share on other sites

in programming, you need to be careful what wording you use. when you mentioned inserting data, that was taken to mean insert data into a database table.

 

what you actually meant is displaying data in the calendar you are outputting on the web page. there's no inserting involved, you are taking data you have at some point in your code and producing html that displays that data the way you want it to be on a web page.

 

using the mysqli code converter to get your code to use the mysqli functions isn't going to get you much sympathy, because it produces messy, lazy, error prone code. learn to actually use the mysqli or PDO statements and rewrite the code yourself.

 

there's a minor problem with the (test) $entries data that's in the code now, in that the data you eventually retrieve from your database table and put into $entries will have leading zero's on the month and day fields and will have - separator characters. by default, unless you do more work to get there, the format will be YYYY-MM-DD. the line of code to build the corresponding $dateKey value will be - 

$dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);

if you change the format of the test data in $entries and the above line of code, this should get your code to display your test data.

 

the next task would be to retrieve the event data from your database table, that matches the $currYear, $currMonth values, and store it into the $entries array in the necessary format.

Link to comment
Share on other sites

Thank you, mac_gyver.  I had to stop and mull over the part about getting me sympathy but I think I get what you mean.  I didn't realize that I was coming across that way.  I just Googled and thought I'd come up with what was needed to progress on this thread so that I could receive help, since gizmola indicated that I wouldn't be able to receive assistance on deprecated code.  I guess I was just trying to move things along on my end, in order to be in a position to receive help, so I'm sorry for that. 

 

Thank you for offering what you did.  I admit that I'm sitting here, blinking stupidly at it (that much should be obvious to everyone) but I'll do my best to successfully do what you've said.  :)

Link to comment
Share on other sites

Hey, Izzy-B I helped you yesterday.

 

You have implemented my suggestions incorrectly. Maybe I wasn't clear enough on what needed to go where. Currently you have just pasted the code I mentions from my post after one another, which has resulted in code duplication and this is why the numbers are appearing below your calendar.

 

So first lets correct your code from yesterday. The code you posted above start of by deleting lines 86 through to 118.

 

 

// calander entries. Use the date as the key (in YYYY/MM/DD format)
$entries = array(
	'2014/8/16' => array(
        				'EVENT',
					),
);
    for ($d=1; $d<=$dim; $d++, $c++) {
 
        if ($c%7==0) echo "</tr><tr>";
 
        $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
 
        $st = ($d == $today) ? "style='padding: 0px;'" : '';
 
        echo "<td class=\"$cl\" $st>\n";
 
        echo "$d" ;
 
        echo "</td>\n";
 
    }
 
// construct the date, this will be used to check to if the key exists in the $entries array
        $dateKey = "$currYear/$currMonth/$d";
        // check if the key exists in the $entries array
        if(array_key_exists($dateKey, $entries)) {
            // for each event, list it in a seperate tool tip
            foreach($entries[$dateKey] as $entry) {
                echo '<div class="has-tooltip">
           Event
            <span class="tooltip">'.$entry.'</span>
        </div>';
            }
        } 

 

 

 

Next replace line 78 with the following (this includes the fix suggested by mac_gver above)

        echo " $d ";
        // construct the date, this will be used to check to if the key exists in the $entries array
        $dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);
        // check if the key exists in the $entries array
        if(array_key_exists($dateKey, $entries)) {
            // for each event, list it in a seperate tool tip
            foreach($entries[$dateKey] as $entry) {
                echo '<div class="has-tooltip">
           Event
            <span class="tooltip">'.$entry.'</span>
        </div>';
            

That was the only edits you need to do so far.

 

Next your query is completely wrong and this is why

 

Your query is not returning any results because your are asking it to return the data from the information field in the events table, problem is you do not have a field called information in your events table (according to the screenshot of the table structure you posted in your first post). The only fields you have in your events table is id, description and startdt. Referencing fields that do not exist in a table will result in an error. You can use the mysqli_error function to retrieve the error from MySQL.

 

The next problem with your query is the WHERE clause. Again you are referencing a field called value which does not exist in your events table. And you are comparing it to the value of an undefined PHP variable called $startdt. This will produce an error from PHP and MySQL.

 

SO delete these lines

$port = ini_get("mysql.default_port");
echo "the port ". $port;
 
    //execute the SQL query and return records
    $result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT information FROM events WHERE value='$startdt', 'description'");
    //fetch tha data from the database
    while ($row = mysqli_fetch_array($result)) {
       echo $row{'startdt, description'};
    }
 
    //close the connection
    ((is_null($___mysqli_res = mysqli_close($con))) ? false : $___mysqli_res);

What you need the query to do is return all the events for the current year and month being shown by the calander, for example if you scroll the calender to September 2014 we only want the events for this date to be returned form the database.

 

Your calendar stores the current calander year and month in the $currYear and $currMonth variables. We can pass the startdt field to MySQL's YEAR and MONTH date aggregate function and compare them to those variables in the WHERE clause so to only return the events that match the calender year and month

 

Sounds complex, but it is not. Add the following

    $currMonth = sprintf('%02d',$currMonth); // pad currMonth with zero's

    // when using user input, always use prepared statements otherwise could lead to SQL injection attacks
    $stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
    $stmt->bind_param('ii', $currYear, $currMonth);

    $stmt->execute();

After these lines in your code

    $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
    $currYear  = isset($_GET['year'])  ? $_GET['year']   : date('Y');
    $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;

Now what we need to get the results from the query and populate the $events array for use, we can do that by using this after $stmt->execute();

    $stmt->bind_result($date, $description);
    $entries = array();
    while ($stmt->fetch()) {
        $entries[$date][] = $description;
    }

Make sure you remove the existing $entries array I told you to add yesterday. You should now find the calendar is listing the events stored in your database.

Link to comment
Share on other sites

Thank you so much, Ch0cu3r.  I am including the edited code and have tried to indent it correctly, because I have two unclosed curly brackets somewhere.  I have tentatively put them where I thought they should go but then panicked and removed them because you have gone to such great lengths to help and I didn't want to add anything to the page without your seeing it first.  There's probably nothing more annoying than people who keep clicking away and randomly changing things while someone's trying to help them. :)

     <?php
$conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "user", "password", "database_")) or die('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
?>
     
    <!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" />
    <link rel="stylesheet" href="css/master.css" type="text/css" media="all">
    <meta http-equiv="Content-Type" content="text/html" />
    <title>Yet Another Test</title>
    </head>
    <body>
    <?php

// calander entries. Use the date as the key (in YYYY/MM/DD format)

$entries = array(
'2014/8/16' => array(
'EVENT',
) ,
);
$currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
$currYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
$today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;
$currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's

// when using user input, always use prepared statements otherwise could lead to SQL injection attacks

$stmt = $conn->prepare('SELECT startdt, description FROM calander WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
$stmt->bind_param('ii', $currYear, $currMonth);
$stmt->execute();
$stmt->bind_result($date, $description);
$entries = array();

while ($stmt->fetch())
{
$entries[$date][] = $description;
}

$prevMonth = $currMonth == 1 ? 12 : $currMonth - 1;
$nextMonth = $currMonth == 12 ? 1 : $currMonth + 1;
$prevYear = $currMonth == 1 ? $currYear - 1 : $currYear;
$nextYear = $currMonth == 12 ? $currYear + 1 : $currYear;
$day1 = mktime(0, 0, 0, $currMonth, 1, $currYear);
$dim = date('t', $day1);
$dayN = mktime(0, 0, 0, $currMonth, $dim, $currYear);
$dow1 = (date('w', $day1) + 0) % 7;
$dowN = (date('w', $dayN) + 0) % 7;
$calHead = date('F Y', $day1);
echo <<<EOT
    <div class="calwrapper">
    <div class="caltitle"><h1>Calendar</h1></div>
    <div class="container">
    <div class="fnl first"></div>
    <div class="adjust"></div>
    <div class="fnl last"></div>
    </div>
    <div class="caldisplay">
    <table cellspacing="0">
    <tr>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
    <td colspan="5" class="adjust">$calHead</td>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
    </tr>
    <tr>
    <th class="we">Sun</th>
    <th class="wd">Mon</th>
    <th class="wd">Tue</th>
    <th class="wd">Wed</th>
    <th class="wd">Thu</th>
    <th class="wd">Fri</th>
    <th class="we">Sat</th>
    </tr>
    <tr>
    EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
    if ($c%7==0) echo "</tr><tr>";
    $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
    $st = ($d == $today) ? "style='padding: 0px;'" : '';
    echo "<td class=\"$cl\" $st>\n";
  echo " $d ";

        // construct the date, this will be used to check to if the key exists in the $entries array

$dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);

// check if the key exists in the $entries array

if(array_key_exists($dateKey, $entries)) {

// for each event, list it in a seperate tool tip

foreach($entries[$dateKey] as $entry) {
echo '<div class="has-tooltip">
Event
<span class="tooltip">'.$entry.'</span>
</div>';

    }
    ?>
    </body>
    </html>

Would you please advise as to whether I have followed your instructions correctly and perhaps guide me toward properly either closing two curly brackets or determining if I have inadvertently created two additional opening curly brackets when editing?  I have 4 open and 2 closed. 

Link to comment
Share on other sites

As it exists now:

     <?php
$conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "user", "password", "database_")) or die('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
?>
     
    <!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" />
    <link rel="stylesheet" href="css/master.css" type="text/css" media="all">
    <meta http-equiv="Content-Type" content="text/html" />
    <title>Yet Another Test</title>
    </head>
    <body>
    <?php

// calander entries. Use the date as the key (in YYYY/MM/DD format)

$entries = array(
'2014/8/16' => array(
'EVENT',
) ,
);
$currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
$currYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
$today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;
$currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's

// when using user input, always use prepared statements otherwise could lead to SQL injection attacks

$stmt = $conn->prepare('SELECT startdt, description FROM calander WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
$stmt->bind_param('ii', $currYear, $currMonth);
$stmt->execute();
$stmt->bind_result($date, $description);
$entries = array();

while ($stmt->fetch())
{
$entries[$date][] = $description;
}

$prevMonth = $currMonth == 1 ? 12 : $currMonth - 1;
$nextMonth = $currMonth == 12 ? 1 : $currMonth + 1;
$prevYear = $currMonth == 1 ? $currYear - 1 : $currYear;
$nextYear = $currMonth == 12 ? $currYear + 1 : $currYear;
$day1 = mktime(0, 0, 0, $currMonth, 1, $currYear);
$dim = date('t', $day1);
$dayN = mktime(0, 0, 0, $currMonth, $dim, $currYear);
$dow1 = (date('w', $day1) + 0) % 7;
$dowN = (date('w', $dayN) + 0) % 7;
$calHead = date('F Y', $day1);
echo <<<EOT
    <div class="calwrapper">
    <div class="caltitle"><h1>Calendar</h1></div>
    <div class="container">
    <div class="fnl first"></div>
    <div class="adjust"></div>
    <div class="fnl last"></div>
    </div>
    <div class="caldisplay">
    <table cellspacing="0">
    <tr>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
    <td colspan="5" class="adjust">$calHead</td>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
    </tr>
    <tr>
    <th class="we">Sun</th>
    <th class="wd">Mon</th>
    <th class="wd">Tue</th>
    <th class="wd">Wed</th>
    <th class="wd">Thu</th>
    <th class="wd">Fri</th>
    <th class="we">Sat</th>
    </tr>
    <tr>
    EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
    if ($c%7==0) echo "</tr><tr>";
    $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
    $st = ($d == $today) ? "style='padding: 0px;'" : '';
    echo "<td class=\"$cl\" $st>\n";
  echo " $d ";

        // construct the date, this will be used to check to if the key exists in the $entries array

$dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);

// check if the key exists in the $entries array

if(array_key_exists($dateKey, $entries)) {

// for each event, list it in a seperate tool tip

foreach($entries[$dateKey] as $entry) {
echo '<div class="has-tooltip">
Event
<span class="tooltip">'.$entry.'</span>
</div>';
     } // close foreach
    } // close if
    }
    ?>
    </body>
    </html> 

I'm now getting an unexpected end of file on line 96.  I would expect to see that error at the end of the file? (By that, I mean, I guess I don't see anything on line 96 that would send the message that the file had ended prematurely.)

Link to comment
Share on other sites

Time to put your troubleshooting skills to work. Make sure you close all braces. I spot one that isn't.

 

If you indent your code, it will make thins like this MUCH easier to spot.

if (some condition)
{
  foreach (something as something_else)
  {
    $x = 1;
    $y = 2;
  }
}

See how they all line up? The if opening and closing brace, the foreach opening/closing brace, and the code indented one more time within them? Visually easy to spot errors like you have.  If everything is mashed up against the left margin...that's a pain to read....and troubleshoot. It makes things harder to figure out.

Link to comment
Share on other sites

Thank you CroNIX!  I do have so much to learn and just when I began to delve into PHP the last week or so, I was told that much of it is changing!  That's a scary proposition.  :)

 

With changing the indentation, I'm still getting the unexpected end of file error. 

     <?php
$conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "user", "password", "database_")) or die('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
?>
     
    <!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" />
    <link rel="stylesheet" href="css/master.css" type="text/css" media="all">
    <meta http-equiv="Content-Type" content="text/html" />
    <title>Yet Another Test</title>
    </head>
    <body>
    <?php

// calander entries. Use the date as the key (in YYYY/MM/DD format)

$entries = array(
'2014/8/16' => array(
'EVENT',
) ,
);
$currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
$currYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
$today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;
$currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's

// when using user input, always use prepared statements otherwise could lead to SQL injection attacks

$stmt = $conn->prepare('SELECT startdt, description FROM calander WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
$stmt->bind_param('ii', $currYear, $currMonth);
$stmt->execute();
$stmt->bind_result($date, $description);
$entries = array();

while ($stmt->fetch())
{
$entries[$date][] = $description;
}

$prevMonth = $currMonth == 1 ? 12 : $currMonth - 1;
$nextMonth = $currMonth == 12 ? 1 : $currMonth + 1;
$prevYear = $currMonth == 1 ? $currYear - 1 : $currYear;
$nextYear = $currMonth == 12 ? $currYear + 1 : $currYear;
$day1 = mktime(0, 0, 0, $currMonth, 1, $currYear);
$dim = date('t', $day1);
$dayN = mktime(0, 0, 0, $currMonth, $dim, $currYear);
$dow1 = (date('w', $day1) + 0) % 7;
$dowN = (date('w', $dayN) + 0) % 7;
$calHead = date('F Y', $day1);
echo <<<EOT
    <div class="calwrapper">
    <div class="caltitle"><h1>Calendar</h1></div>
    <div class="container">
    <div class="fnl first"></div>
    <div class="adjust"></div>
    <div class="fnl last"></div>
    </div>
    <div class="caldisplay">
    <table cellspacing="0">
    <tr>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
    <td colspan="5" class="adjust">$calHead</td>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
    </tr>
    <tr>
    <th class="we">Sun</th>
    <th class="wd">Mon</th>
    <th class="wd">Tue</th>
    <th class="wd">Wed</th>
    <th class="wd">Thu</th>
    <th class="wd">Fri</th>
    <th class="we">Sat</th>
    </tr>
    <tr>
    EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
    if ($c%7==0) echo "</tr><tr>";
    $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
    $st = ($d == $today) ? "style='padding: 0px;'" : '';
    echo "<td class=\"$cl\" $st>\n";
  echo " $d ";

        // construct the date, this will be used to check to if the key exists in the $entries array

$dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);

// check if the key exists in the $entries array

if(array_key_exists($dateKey, $entries)) 
{

// for each event, list it in a seperate tool tip

  foreach($entries[$dateKey] as $entry) 
  {
	echo '<div class="has-tooltip">
	Event
	<span class="tooltip">'.$entry.'</span>
	</div>';
  }
} 
}
    
    ?>
</body>
</html>

Am I correct that the final closing curly bracket responds to this line?

    for ($d=1; $d<=$dim; $d++, $c++) {

The line numbers may change slightly from changing the indentation, etc., but the error always refers to the end of this line of code, (specifically, the last line of it, containing only the opening curly bracket):

foreach($entries[$dateKey] as $entry)
{
Link to comment
Share on other sites

So sorry to reply rather than edit, but my edit function seems to be gone.  I just wanted to add that I have 51 open and 51 closed parentheses and 4 open and 4 closed curly brackets.  I'm reading the manual now to try to determine what else causes "end of file" errors.

Link to comment
Share on other sites

I doubt you will find help for that in the manual.  You simply missed a bracket somewhere.

Hi, ginerjm, and thank you.  If the count tallies correctly, would it be a case of my mismatching them, then?  I also looked at this bit of code:

	echo '<div class="has-tooltip">
Event
<span class="tooltip">'.$entry.'</span>
</div>';

...thinking that perhaps the single quotes around .$entry. were causing it, since a single quote is begun at echo '<div class but trying to use \'.$entry.\' didn't change things. 

 

I have an even count of both open and closed parentheses and curly brackets.  Would I then begin trying to determine if they're simply misplaced?  For instance, I wondered if this bit of code:

    for ($d=1; $d<=$dim; $d++, $c++) {

was meant to close at the very end of the file?  (Because if it is, then I need to learn why.)  :)

Link to comment
Share on other sites

I think, after going back and carefully staring at what Ch0cu3r said, I realize that he'd edited and that I wasn't meant to include the $events array at all, at this point.  That seems to have fixed the error, I believe...   I'm uploading now. 

Link to comment
Share on other sites

The error is caused by line 76

    EOT;

Remove the four spaces before EOT;

 

The closing delimiter must not have any characters (including white space, expect a line break) before it. It must be on its own line starting from the very first column of next line

Link to comment
Share on other sites

I'm not getting any errors with this:

 <?php
$conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "user", "password", "database_")) or die('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
?> 
  <!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" />
<link rel="stylesheet" href="css/master.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html" />
<title>Yet Another Test</title>
</head>
<body>
<?php
$currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
$currYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
$today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;
$currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's

// when using user input, always use prepared statements otherwise could lead to SQL injection attacks

$stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
$stmt->bind_param('ii', $currYear, $currMonth);
$stmt->execute();
$currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's

// when using user input, always use prepared statements otherwise could lead to SQL injection attacks

$stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
$stmt->bind_param('ii', $currYear, $currMonth);
$stmt->execute();
$prevMonth = $currMonth == 1 ? 12 : $currMonth - 1;
$nextMonth = $currMonth == 12 ? 1 : $currMonth + 1;
$prevYear = $currMonth == 1 ? $currYear - 1 : $currYear;
$nextYear = $currMonth == 12 ? $currYear + 1 : $currYear;
$day1 = mktime(0, 0, 0, $currMonth, 1, $currYear);
$dim = date('t', $day1);
$dayN = mktime(0, 0, 0, $currMonth, $dim, $currYear);
$dow1 = (date('w', $day1) + 0) % 7;
$dowN = (date('w', $dayN) + 0) % 7;
$calHead = date('F Y', $day1);
echo <<<EOT
     <div class="calwrapper">
     <div class="caltitle"><h1>Calendar</h1></div>
     <div class="container">
     <div class="fnl first"></div>
     <div class="adjust"></div>
     <div class="fnl last"></div>
     </div>
     <div class="caldisplay">
        <table cellspacing="0">
        <tr>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
        <td colspan="5" class="adjust">$calHead</td>
        <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
        </tr>
        <tr>
          <th class="we">Sun</th>
          <th class="wd">Mon</th>
          <th class="wd">Tue</th>
          <th class="wd">Wed</th>
          <th class="wd">Thu</th>
          <th class="wd">Fri</th>
          <th class="we">Sat</th>
         </tr>
        <tr>
EOT;

for ($d = 0; $d < $dow1; $d++) echo "<td class=\"hd\"> </td>";
$c = $dow1;

for ($d = 1; $d <= $dim; $d++, $c++)
{
if ($c % 7 == 0) echo "</tr><tr>";
$cl = ($c % 7 == 5) || ($c % 7 == 6) ? 'we' : 'wd';
$st = ($d == $today) ? "style='padding: 0px;'" : '';
echo "<td class=\"$cl\" $st>\n";
echo " $d ";

// construct the date, this will be used to check to if the key exists in the $entries array

$dateKey = sprintf('%04d-%02d-%02d', $currYear, $currMonth, $d);

// check if the key exists in the $entries array

if (array_key_exists($dateKey, $entries))
{

// for each event, list it in a seperate tool tip

foreach($entries[$dateKey] as $entry)
{
echo '<div class="has-tooltip">
    Event
    <span class="tooltip">' . $entry . '</span>
    </div>';
echo "</td>\n";
}

while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>';
echo "</tr></table>\n";
echo '</div></div>';
} // close foreach
} // close if

?>
</body>
</html>
	 

But the page is loading like this:  TEST

 

I have double-checked login credentials in case that was the issue.  The page source just stops abruptly after the opening body tag:


  
  <!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" />
<link rel="stylesheet" href="css/master.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html" />
<title>Yet Another Test</title>
</head>
<body>

So you'd think I'd be throwing errors?  :-\

Link to comment
Share on other sites

I went back to the code I had posted here:  http://forums.phpfreaks.com/topic/290477-got-great-help-here-but-having-trouble-implementing/?do=findComment&comment=1487954

 

I took a fresh empty text editor and copied that code exactly as it is on that link.  Then I removed the four spaces from line 76 so that the code now looks like this:

     <?php

    $conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "user", "password", "database_")) or die('Cannot connect to the database because: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
    ?>
    <!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" />
    <link rel="stylesheet" href="css/master.css" type="text/css" media="all">
    <meta http-equiv="Content-Type" content="text/html" />
    <title>Yet Another Test</title>
    </head>
    <body>
    <?php
     
    // calander entries. Use the date as the key (in YYYY/MM/DD format)
     
    $entries = array(
    '2014/8/16' => array(
    'EVENT',
    ) ,
    );
    $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n');
    $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y');
    $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;
    $currMonth = sprintf('%02d', $currMonth); // pad currMonth with zero's
     
    // when using user input, always use prepared statements otherwise could lead to SQL injection attacks
     
    $stmt = $conn->prepare('SELECT startdt, description FROM calander WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');
    $stmt->bind_param('ii', $currYear, $currMonth);
    $stmt->execute();
    $stmt->bind_result($date, $description);
    $entries = array();
     
    while ($stmt->fetch())
    {
    $entries[$date][] = $description;
    }
     
    $prevMonth = $currMonth == 1 ? 12 : $currMonth - 1;
    $nextMonth = $currMonth == 12 ? 1 : $currMonth + 1;
    $prevYear = $currMonth == 1 ? $currYear - 1 : $currYear;
    $nextYear = $currMonth == 12 ? $currYear + 1 : $currYear;
    $day1 = mktime(0, 0, 0, $currMonth, 1, $currYear);
    $dim = date('t', $day1);
    $dayN = mktime(0, 0, 0, $currMonth, $dim, $currYear);
    $dow1 = (date('w', $day1) + 0) % 7;
    $dowN = (date('w', $dayN) + 0) % 7;
    $calHead = date('F Y', $day1);
    echo <<<EOT
    <div class="calwrapper">
    <div class="caltitle"><h1>Calendar</h1></div>
    <div class="container">
    <div class="fnl first"></div>
    <div class="adjust"></div>
    <div class="fnl last"></div>
    </div>
    <div class="caldisplay">
    <table cellspacing="0">
    <tr>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
    <td colspan="5" class="adjust">$calHead</td>
    <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
    </tr>
    <tr>
    <th class="we">Sun</th>
    <th class="wd">Mon</th>
    <th class="wd">Tue</th>
    <th class="wd">Wed</th>
    <th class="wd">Thu</th>
    <th class="wd">Fri</th>
    <th class="we">Sat</th>
    </tr>
    <tr>
EOT;
    for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
    $c = $dow1;
    for ($d=1; $d<=$dim; $d++, $c++) {
    if ($c%7==0) echo "</tr><tr>";
    $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
    $st = ($d == $today) ? "style='padding: 0px;'" : '';
    echo "<td class=\"$cl\" $st>\n";
    echo " $d ";
     
    // construct the date, this will be used to check to if the key exists in the $entries array
     
    $dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d);
     
    // check if the key exists in the $entries array
     
    if(array_key_exists($dateKey, $entries))
    {
     
    // for each event, list it in a seperate tool tip
     
    foreach($entries[$dateKey] as $entry)
    {
    echo '<div class="has-tooltip">
    Event
    <span class="tooltip">'.$entry.'</span>
    </div>';
    }
    }
    }
    ?>
    </body>
    </html>

The reason I edited the file before was because when I went back to look again carefully at your instructions, I noted that, although you had told me that the $entries array could be added "anywhere above line 30" in my code, you had since edited your post so that there is now no mention of adding the $entries array.  Only this: 

 

 

Make sure you remove the existing $entries array I told you to add yesterday.

 

Removing the $entries array caused the error to go away (although, as I said, the page wasn't fully loading).  Adding it back now, of course, as you said,  removing the 4 spaces has sorted the error, even though the page is still not loading as it should.  The code I've just shown is exactly what I've just uploaded, with the exception of my altering my login credentials for the purposes of posting here. 

 

I apologize for trying your patience.  I appreciate your help, but I understand if you'd rather I hit the bricks.

 

Thank you.

Link to comment
Share on other sites

If you'll forgive one last question; if the PHP is not throwing errors, is it possible that, since the div class "tooltips" involves CSS, that perhaps something problematic with CSS might be affecting the page, once the PHP calls for that div?  I've not given attention to the CSS, because the page has always loaded just fine before and I did know for sure that the PHP needed work, but now PHP is calling for that div and that's the only thing I can think of (if you agree with the validator that the PHP file is clean). 

 

I apologize again, for being a bit slow.  I'm only very recently post-surgery (spine) and I tend to grow weary as the day progresses.  I get a bit dense.  If you'd weigh in on my CSS question, I'll try to sort it and thank you again.

Link to comment
Share on other sites

your online test page stops producing output after the <body> tag. that's a sign you are getting a fatal php runtime error prior to any php echo statements. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects?

 

edit: especially since your database table name is not calendar.

Link to comment
Share on other sites

I think the problem is with the query. You have table called events not calander. Make sure you referencing the correct table name in your query.

$stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?');

At this point your code is correct. The problem is just making sure you are using the correct database credentials and the query is referencing the correct table and column names.

Link to comment
Share on other sites

I just flat out love you guys.  :-*

 

Yes....  events, not calender.  My goodness.  I just get so progressively foggy with all the meds they're making me take, that I absolutely never saw that. 

 

Thank you all for being so patient with me and so kind.  I'm sure I'm the most annoying poster you've ever had.  Will there be prizes?  :)

 

Check out my page!

 

Of course, the information in the tooltip won't say "Event" but you get the idea.  And I'll have to end up using another tooltip I've been testing because this one doesn't work on IOS and the other does (though not as neat).  I'll have to tweak the cosmetics a bit.

 

I just cannot thank you enough.  This is the kindest forum, to date, I've sought any kind of help from. 

Link to comment
Share on other sites

I just flat out love you guys.  :-*

 

 

 

I just cannot thank you enough.  This is the kindest forum, to date, I've sought any kind of help from. 

 

Glad you got things working, and the words of thanks for the members who tirelessly help people out, are much appreciated, and rarely acknowledged.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.