PHP Variable Assignment Issue

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
User avatar
bradbury
Forum Commoner
Posts: 40
Joined: Wed Aug 25, 2010 11:21 am
Location: Eugene, OR

PHP Variable Assignment Issue

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Variable Assignment Issue

Post by AbraCadaver »

What is $indiv? Is it supposed to hold a javascript variable name?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
bradbury
Forum Commoner
Posts: 40
Joined: Wed Aug 25, 2010 11:21 am
Location: Eugene, OR

Re: PHP Variable Assignment Issue

Post 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
aftabnaveed
Forum Newbie
Posts: 9
Joined: Sat Sep 30, 2006 1:05 am

Re: PHP Variable Assignment Issue

Post 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
User avatar
bradbury
Forum Commoner
Posts: 40
Joined: Wed Aug 25, 2010 11:21 am
Location: Eugene, OR

Re: PHP Variable Assignment Issue

Post 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
Post Reply