Month: September 2015

Mixing javascript with php

· Updates · Comments Off on Mixing javascript with php

After working on a big project.

I learned how to work with different langauges (mysql, javascript, and PHP).

First of all javascript can’t call mysql, but you can do some nifty tricks with php and javascript.

Samples bellow:

<script language=javascript>
var jsvar;

jsvar = <?php echo $phpvar;?>
</script>

OR

<script language=javascript>

<?php ?>

</script>

Example:

<?php if(isset($books)): ?>
<script type=”text/javascript”>
$(window).load(function()
{

$(‘.mydate1’).glDatePicker(
{
showAlways: true,
allowMonthSelect: true,
allowYearSelect: true,
prevArrow: ”,
nextArrow: ”,
selectableDateRange: [
{ from: new Date(),
<?php foreach($books as $book): ?>
<?php
$checks_in = date(‘Y, n, d’, strtotime(‘-1 month’, strtotime(‘-1 day’, strtotime($book->check_in))));
$checks_out = date(‘Y, n, d’, strtotime(‘-1 month’, strtotime(‘+1 day’, strtotime($book->check_out))));
?>
to: new Date(<?php echo $checks_in; ?>) },
{ from: new Date(<?php echo $checks_out; ?>),
<?php endforeach; ?>
to: new Date(2055, 8, 24) },
],
});
});
</script>
<?php endif; ?>