How to insert PHP code between javascript code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

How to insert PHP code between javascript code?

Post by azhan »

Hey Guys,

Currently I already have a calender generated by javascript which display days and months and i already make each day displayed could be link to another page once the day been clicked.
My problem is, I wanted to include php code inside the generated javascript calender which read the sql database on which day is already full booked. If the respective day is already fully book, i want the day to display "FULL" on the calender right below the day displayed.

I do understand that javascript only runs on the client-side environment while php runs on the server-side environment. But, is there any way that i could make this happen?

Consider this is my code

<script: javascript>
.... calender js code
.... calender js code
.... calender js code
.....calender js code
....
<?php
$date = "'+Day_Counter+'Label_Month[Month]'+'Year+'"; /// Code from javascript
$check =mysql_query("SELECT * FROM appointment WHERE date=$date");
$cheking = mysql_num_rows($check);
if( $checking >= 18 ) {
echo "FULL";
}
?>
...... calender js code
...... calender js code
...... calender js code
...... calender js code
...... calender js code
</script>
jtown
Forum Newbie
Posts: 2
Joined: Thu Jan 22, 2009 7:59 pm
Location: Srilanka
Contact:

Re: How to insert PHP code between javascript code?

Post by jtown »

I also had a problem like this :banghead:
but

<script: javascript>
.... calender js code
.... calender js code
.... calender js code
.....calender js code
....

Code: Select all

<?php
$date = "'+Day_Counter+'Label_Month[Month]'+'Year+'"; /// Code from javascript
$check =mysql_query("SELECT * FROM appointment WHERE date=$date");
$cheking = mysql_num_rows($check);
if( $checking >= 18 ) {
echo "FULL";
}
?>
...... calender js code
...... calender js code
...... calender js code
...... calender js code
...... calender js code
</script>
this technique worked for me !!!
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: How to insert PHP code between javascript code?

Post by JAB Creations »

Code: Select all

<?php
echo "var my_var1 = 'some text';\n";
echo "var my_var2 = 'some text';\n";
?>
 
function my_function(<?php echo $some_parameter_name_here;?>)
{
//etc etc
}
Post Reply