Jump to content


Photo

Embedding PHP in HTML "'". '. ". problems


  • Please log in to reply
10 replies to this topic

#1 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 03:54 PM

Hi all,

Just a quick question, Im sure it is very simple, I have a line of HTML code that calls a javascript function. The function basically scrolls layers. In order to scroll the javascript is sent a number of variable including in my case

A layer
and a value to scroll down to

the code below is a sample of the code which works.

onMouseOver="P7AniMagic('initial',0,-200,5,30,0,0)"

the two key values are the word initial and the -200.

the initial is the name of the layer I wish to scroll and -200 is by how much I wish to scroll.

for each of these I need to send values to in the form of variables so any layer can be scrolled any distance.

I can replace the -200 with the variable $ScrollVal

onMouseOver="P7AniMagic('initial',0,<?php echo $ScrollVal; ?>,5,30,0,0)"

this works fine, i then want to replace the layer name in the following way.

onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)"

This does not work, Im sure I have some of the "'". the wrong way around.

Can anyone tell me how this should be wrote for characters, I seem to have managed the numbers by the $ScrollVal variable working okay.

The full code for that line is below

<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>


Many Thanks
jamie




#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 04:00 PM

Rather than going in and out of PHP mode. Use HEREDOC to echo out the HTML for the scroller:
echo <<<SCROLLER
<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('{$Layer2Scroll}',0,{$ScrollVal},5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>
SCROLLER;
// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE!


#3 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 06:52 PM

hi
many thanks for your reply, I have never used that technique before. Wil lthis solve the problem I am having trying to get. Layer variable to be read as its value?

Many Thanks
Jamie

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 06:58 PM

Not sure but try the code out first and see if it works. However It should do. All I've done is taken your code and put it into a big echo statement.

#5 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 07:24 PM

hi again wildteen

The page recgnised the echo, but again the layer did not scroll, its still the $layer2Scroll variable that is causing me problems, if I just replace the '{layer2scroll}'  with 'initial' its works fine.

So I still need to get the value of the variable to be read as text. What do you reckon.

Thanks
Again

#6 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 14 September 2006 - 07:52 PM

look page source in your browser
is it look OK?

#7 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 08:08 PM

Hi Sasa

I cant tell, due to the fact that the function is in an external file, that is included. So when i view source i only get the info for that page i think.

onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('',0,-2000,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">

altoguh i did find this code

#8 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 14 September 2006 - 08:17 PM

is it variable $Layer2Scroll set up
try change
<?php echo "'".$Layer2Scroll."'" ?>
to
<?php $Layer2Scroll='initial'; echo "'".$Layer2Scroll."'" ?>
if it works, check twice thet yuor variable have good value

#9 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 08:33 PM

sasa

that worked okay,

thats when I set the variable within the code


<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php $Layer2Scroll='initial'; echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>

it also works when I do the below

$Layer2Scroll = "initial";

then

<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>

but will not work when I send the variable $Layer2Scroll to the whole function as below

function scroller_set($upval,$Layer2Scroll)
{
echo "Layer ".$Layer2Scroll;
$ScrollVal = $upval * -2000;

echo $scrollval;



?>
<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>
<?php
}


even though the echo statement

echo "Layer ".$Layer2Scroll;

is revealing

initial

I just dont get it, am I missing somethnig.

Thanks for your help i feel we are getting closer.



#10 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 14 September 2006 - 10:00 PM

I have just checked my variable type using the code below

$varTyi = gettype($Layer2Scroll);
echo $varTyi;

and it is a string.

#11 notonurnelly

notonurnelly
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 15 September 2006 - 09:29 AM

Im still struggling with this, does anyone have any fresh ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users