Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, question is answered. For those who want to know what I have, here it is.</p> <p>To change a Start Date and an End Date (A date range if you will) into an array of individual dates, I used this:</p> <pre><code>function createDateRangeArray($strDateFrom,$strDateTo) //Changes a Range of Dates to Specific Dates { static $aryRange = array(); //Creates an Array $iDateFrom = mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4)); $iDateTo = mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4)); if ($iDateTo &gt;= $iDateFrom) { array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry while ($iDateFrom&lt;$iDateTo) { $iDateFrom += 86400; // add 24 hours array_push($aryRange,date('Y-m-d',$iDateFrom)); } } return $aryRange; //Returns to step 1 and adds another value into the array } </code></pre> <p>To get every date from my SQL Database and push them into a single array, this was used:</p> <pre><code>$query = "SELECT startdate, enddate FROM classdetails"; $results = mysql_query($query); while ($arrays = mysql_fetch_array($results)) { $aryDates = createDateRangeArray($arrays['startdate'],$arrays['enddate']); echo "&lt;br /&gt;"; } </code></pre> <p>So now I have managed to get every date range from an entire list of classes and made one huge array. Now I had to use this array to actually disable the dates. Using the functions of which Yi Jiang has no generously wrote (thank you to everyone who helped me), the next step is:</p> <pre><code>$(function() { //To enable End Date picker only when Start Date has been chosen (And to disable all dates prior of said date) var end = $('#enddate').datepicker( {numberOfMonths: 3, beforeShowDay: checkAvailability,}); // Defining a function, because we're binding this to two different events function enableEnd() { end.attr('disabled', !this.value.length) // Enable the end input element if the first one has anything in it .datepicker('option', 'minDate', this.value); // Set the minimum date to the date in the first input } //End of function // Datepicker $('#startdate').datepicker({ numberOfMonths: 3, beforeShowDay: checkAvailability, onSelect: enableEnd // Call enableEnd when a date is selected in the first datepicker }).bind('input', enableEnd); // Do the same when something is inputted by the user //hover states on the static widgets $('#dialog_link, ul#icons li').hover( function() {$(this).toggleClass('ui-state-hover');} ); }); //End of Function //Disabling all dates where selected room and speaker is unavailable var $myBadDates = new Array (&lt;?php foreach($aryDates as $disabledate) { echo " \"$disabledate\","; } echo " 1"; ?&gt;); //Creates the array (The echo " 1"; is merely to close the array and will not affect the outcome function checkAvailability(mydate){ var $return=true; var $returnclass ="available"; $checkdate = $.datepicker.formatDate('yy-mm-dd', mydate); for(var i = 0; i &lt; $myBadDates.length; i++) { if($myBadDates[i] == $checkdate) { $return = false; $returnclass= "unavailable"; } } return [$return,$returnclass]; } //End of function </code></pre> <p>The only thing in my body right now, for testing purposes, are:</p> <pre><code> &lt;!-- Datepicker --&gt; &lt;h2 class="header"&gt;Datepicker&lt;/h2&gt; &lt;span&gt; Start Date: &lt;input type="text" id="startdate" /&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;span&gt; End Date: &lt;input type="text" id="enddate" disabled="disabled" /&gt; &lt;/span&gt; </code></pre> <p>It's long, yes, but it works. Thank you to everyone who helped me get this working. The edit was me changing a function to a JQuery function that exists (of which for some reason I did not use in the first place); toggleClass. Thanks for picking that out.</p>
    singulars
    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