Page 1 of 1
PHP Variable Assignment Issue
Posted: Tue Aug 31, 2010 1:08 pm
by bradbury
The file is being read as a javascript file through
<script language="JavaScript" src="js/calendar.php"></script>
and now I'm trying to assign a value of a variable $indiv to a variable that was declared in a function but for some reason I can't manage to get it to work
Code: Select all
<?php
Header("content-type: application/x-javascript");
//Constructor
echo "function calendar(id,d,p){
this.id = id;";
$indiv; echo "= p; <----- I dont know how to make that call properly
...
...
Thank you in advance
Re: PHP Variable Assignment Issue
Posted: Tue Aug 31, 2010 1:54 pm
by AbraCadaver
What is $indiv? Is it supposed to hold a javascript variable name?
Re: PHP Variable Assignment Issue
Posted: Tue Aug 31, 2010 2:14 pm
by bradbury
$indiv is supposed to be called later on in the script in a php section that checks for the id of the object. And since I am using php logic to figure out some of this stuff I need a php variable to complete the logic.
I also read somewhere that this is impossible to do since php is server sided and javascript is client sided. So if this is the case is there a way to assign the variable within the php? If it is possible I was thinking that something to this extent would work:
Code: Select all
$indiv = print("<script type="text/javascript">p</script>");
however when I tried this I got a syntax error saying that $indiv wasn't assigned a value. So i have no idea what I should do
Re: PHP Variable Assignment Issue
Posted: Tue Aug 31, 2010 4:33 pm
by aftabnaveed
You can render javascript from PHP but not can't render PHP from javascript, $indiv seems to be a PHP variable so you can use it to hold a javascript string. and then render it when required.
Hope that helps.
Thanks
Re: PHP Variable Assignment Issue
Posted: Tue Aug 31, 2010 4:39 pm
by bradbury
yeah that makes sense. Thank you. That was just the answer I didn't want to hear though. Since the only reason I need this variable is because it holds the id value that I want to use to search my database with and if I dont have a way to identify the search by anything it makes it a little hard to have the program work properly. So now I think I might just have to reprogram the whole thing in PHP so that I dont have to deal with this again. Well luckily it's already written in javascript