Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp and MySQL calendar modification
    primarykey
    data
    text
    <p>This code creates a nice <strong>calendar</strong> (<a href="http://www.newmediacampaigns.com/page/create-a-jquery-calendar-with-ajax-php-and-a-remote-data-source" rel="nofollow">original code</a>), but I'm trying to make some modifications on it. The first lines are ok, no need to pay attention to that, but here it is: </p> <pre><code>$calendar = '&lt;table cellpadding="0" cellspacing="0" class="calendar"&gt;'; $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $calendar.= '&lt;tr class="calendar-row"&gt;&lt;td class="calendar-day-head"&gt;'.implode('&lt;/td&gt;&lt;td class="calendar-day-head"&gt;',$headings).'&lt;/td&gt;&lt;/tr&gt;'; $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); $calendar.= '&lt;tr class="calendar-row"&gt;'; for($x = 0; $x &lt; $running_day; $x++): $calendar.= '&lt;td class="calendar-day-np"&gt; &lt;/td&gt;'; $days_in_this_week++; endfor; </code></pre> <p>Here is where I stucked. From now on, the calendar access the <strong>database</strong> and print my dates based on the events I have recorded. For the dates that the query has found any event, than the code prints a link in it. See the code:</p> <pre><code>$db = new PDO('mysql:host=localhost;dbname=calendar','root',''); $stmt = $db-&gt;prepare('SELECT time, title FROM events'); $stmt-&gt;execute(); $rawTimeStamps = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC); $cleanDateArray = array(); foreach ($rawTimeStamps as $t) { $rawDate = $t['time']; $rawDate = getdate($rawDate); $cleanDate = mktime(0,0,0,$rawDate['mon'],$rawDate['mday'],$rawDate['year']); $cleanDataArray[] = $cleanDate; } for($list_day = 1; $list_day &lt;= $days_in_month; $list_day++): $calendar.= '&lt;td class="calendar-day"&gt;'; $timestamp = mktime(0,0,0,$month,$list_day,$year); if (in_array($timestamp, $cleanDataArray)) { $calendar.= '&lt;div class="day-number day-number-event"&gt;&lt;a href="#"&gt;'.$list_day.'&lt;/a&gt;&lt;/div&gt;'; } else { $calendar.= '&lt;div class="day-number day-number-noevent"&gt;'.$list_day.'&lt;/div&gt;&lt;/div&gt;&lt;div id="calendar-events"&gt;&lt;/div&gt;'; } $calendar.= '&lt;/td&gt;'; if($running_day == 6): $calendar.= '&lt;/tr&gt;'; if(($day_counter+1) != $days_in_month): $calendar.= '&lt;tr class="calendar-row"&gt;'; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; </code></pre> <p>And than, the code finishes the calendar.</p> <pre><code>if($days_in_this_week &lt; 8): for($x = 1; $x &lt;= (8 - $days_in_this_week); $x++): $calendar.= '&lt;td class="calendar-day-np"&gt; &lt;/td&gt;'; endfor; endif; $calendar.= '&lt;/tr&gt;'; $calendar.= '&lt;/table&gt;'; return $calendar; </code></pre> <p>What I need is to print other infos from the database related to the date that has an event. In other words, all I want is to print the events title (that are also recorded in a column of the events table) right below the event data. Something like:</p> <pre><code>$calendar.= '&lt;div class="day-number day-number-event"&gt;&lt;a id="'.$timestamp.'" href="#"&gt;'.$list_day.'&lt;/a&gt;&lt;/div&gt;&lt;p&gt;'.$title.'&lt;/p&gt;';} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload