Jump to content

(SOLVED) Embedding PHP within HTML/ Javascript (Quick Question?)


Solarpitch

Recommended Posts

Hey Guys,

Just wanted to know if the following format is correct, doesnt seem to be working for me at all.

[code]

<?php

$image1 = "fusion_02.jpg";
$image2 = "fusion_03.jpg";
$image3 = "fusion_04.jpg";

?>

function image (img)
{
document.images['image'].src = img;
}

<a href="javascript:image('designs/"<?php $image1; ?>"');">1</a>
<a href="javascript:image('designs/"<?php $image2; ?>"');">2</a>
<a href="javascript:image('designs/"<?php $image3; ?>"');">3</a>
[/code]

Bascially, it changes the image on a page based on the number that is selected. It seems to work when I have it like below, but not above. Just wondering if the above is the correct way to embed the PHP content?

This way works fine...
[code]
<a href="javascript:image('designs/fusion_03.jpg');">1</a>
<a href="javascript:image('designs/fusion_03.jpg');">2</a>
<a href="javascript:image('designs/fusion_04.jpg');">3</a>
[/code]
Link to comment
Share on other sites

The default image will be the first image in the result. There will be 3 images displayed and $image 1 will be the default. I also have the following line of code in my "php_database" page.

[code]
<img name='image' src='designs/".$image1."' style='border: 1px solid rgb(0, 0, 0);' border='0' width='200' height='200' title='blah' />
[/code]
Link to comment
Share on other sites

Why do you have the double quotes surrounding the value echoed via PHP?
[code]
<a href="javascript:image('designs/"<?php echo $image1; ?>"');">1</a>
<a href="javascript:image('designs/"<?php echo $image2; ?>"');">2</a>
<a href="javascript:image('designs/"<?php echo $image3; ?>"');">3</a>
[/code]

Remove those double quotes and it should be ok:
[code]
<a href="javascript:image('designs/<?php echo $image1; ?>');">1</a>
<a href="javascript:image('designs/<?php echo $image2; ?>');">2</a>
<a href="javascript:image('designs/<?php echo $image3; ?>');">3</a>
[/code]

Ken
Link to comment
Share on other sites

Hi Guys,

Na . . I tried that already! Still no Joy . . I bet its something god dam simple . . heres my code again

view_ad.php
[code]

<?php
$image1 = "fusion_02.jpg"; //I'll be calling these from a DB when I get it working
$image2 = "fusion_03.jpg";
$image3 = "fusion_04.jpg";
?>

script>

function image (img) {
document.images['image'].src = img;
}

</script>

<a href="javascript:image('designs/<?php echo $image1; ?>');">1</a>
<a href="javascript:image('designs/<?php echo $image2; ?>');">2</a>
<a href="javascript:image('designs/<?php echo $image3; ?>');">3</a>
[/code]

php_database.php
[code]
<h1 class='underline'>New Callaway Big Bertha <span>(Uploaded on: 17-12-2006)</span?></br>
<div id='container'>
<h1 class='underline'>
<div id='images'>



  <img name='image' src='designs/".$image1."' style='border: 1px solid rgb(0, 0, 0);' border='0' width='200' height='200' title='blah' />
 
The above line displays the image
****************************************

</div>
<div id='details'>
  <ul>
  <li><span>Section:</span> Mens</li>
  <li><span>Class:</span> Drivers</li>
  <li><span>Make:</span> Callaway</li>
  </ul>
  <ul>
  <li><span>Tel:</span> 0876141487</li>
  <li><span>Contact Name:</span> Andrew</li>
  <li><span>County:</span> Dublin</li>
  </ul>
</div>
<div id='text'>
  <p>  Brand new Callaway Big Bertha Driver. Comes with 65 stiff graffaloy shaft, 9 degree loft and original head cover. No Time wasters, first to see will buy. <div class='clearb'></div>
<h2 class='underline'>Price: &euro;400
</div>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.