Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript jqeury why does my array not exist?

220061

Well-Known Coder
Hello I'm trying to loop through my php array in jqeury but when I do that it days it doesn't exist. this is weird to me because I'm able to use the array to create an variable in jqeury. I need a loop that starts at the first date, and adds 1 day until it reaches the end date.
the php code
PHP:
$huis_ID = $_GET['ID'];
 $arraysession=array();
 $sql = "SELECT start_datum, eind_datum FROM reserveringen WHERE huis_ID = ?";
 $stmt = $conn->prepare($sql);
 $stmt->bind_param("i", $huis_ID);
 $stmt->execute();
 $result = $stmt->get_result();
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
      
         $start_datum = date('d-m-Y', strtotime($row['start_datum']));
      
         $eind_datum = date('d-m-Y', strtotime($row['eind_datum']));
        array_push($arraysession, $start_datum, $eind_datum);
    
 }

   $array_to_json=json_encode((array)$arraysession);
   ?>

jqeury
JavaScript:
  var dates = <?php echo $array_to_json ?>; // this part works
    console.log(dates);
    function disableDates(date) {
        var string = $.datepicker.formatDate('dd-mm-yy', date);
// this doesn't work because it doesn't understand what $array_to_json is 
        for(var i = dates; i < <?php $array_to_json ?>. length ; i++){
        
        console. log(i);
        
        }
    
        return [dates.indexOf(string) == -1];
    }
 
In your variable naming the $array_to_json it includes "echo" whereas your for loop does not.

JavaScript:
//Your var declaration and for loop
var dates = <?php echo $array_to_json ?>;
for(var i = dates; i < <?php $array_to_json ?>. length ; i++)

// Proper for loop name
var dates = <?php echo $array_to_json ?>;
for(var i = dates; i < <?php echo $array_to_json ?>. length ; i++)

Give that a shot and let us know
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom