Jump to content

Recommended Posts

Hi.

How can i achieve this?

 

<script language="JavaScript" type="text/javascript">

function CngPicture(bilde){ 
Movies= document.getElementById('movies');
    Index = Movies.selectedIndex; 
Value = Movies.options[index].value;

<?php
$query = "SELECT picture FROM `movies` WHERE id='"?> Value <?php "'"; 
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$picture = $row['picture'];
?>

document.getElementById('bilde').src='<?php echo $picture; ?>';
}
</script>

 

Any help is appreciated.

Regards Morten.

Link to comment
https://forums.phpfreaks.com/topic/146513-javascript-with-php-problem/
Share on other sites

Yes, i do think i have to use AJAX after what i've read on the web.

 

But i have never used AJAX before.

So any help on building that code would be appreciated.

 

Øhm.. How should i explain my issue..

I am trying to get a link(Picture) from a database where the link is changing depending to the Dropdown value into a javascript code.. The dropdown value is the same as the Movie ID in the database.

 

 

or, you need to use a PHP handler script to return the images....let me see if i can explain:

 

in your script, your JS would look like this:

<script language="JavaScript" type="text/javascript">
  function CngPicture(bilde){
    Movies = document.getElementById('movies');
    Index = Movies.selectedIndex;
    Value = Movies.options[index].value;
    document.getElementById('bilde').src = 'movieImage.php?id=' + Value;
  }
</script>

 

then, create a file called movieImage.php with the following code:

<?php
  //Put your MySQL Connection info here

  $id = mysql_real_escape_string($_GET['id']);
  $query = "SELECT picture FROM `movies` WHERE id='$id'";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  header('Location: '. $row['picture']);
  exit;
?>

Oh damn!

It works!

 

Thanks alot!

 

 

 

Hm, the picture got the link: http://www.vinstrakino.co.cc/php/movieImage.php?id=100 on the first selected dropdown (the id is correct)

(the link returns the correct picture, so it has to be something with the javascript?)

 

It didnt return the link from the database.

 

Anything ive done wrong?

 

<script language="JavaScript" type="text/javascript">
  function CngPicture(bilde){
    Movies = document.getElementById('movies');
    Index = Movies.selectedIndex;
    Value = Movies.options[index].value;
    document.getElementById('bilde').src = 'php/movieImage.php?id=' + Value;
  }
</script>

 

 

<?php
  require 'tilkobling.php';

  $id = mysql_real_escape_string($_GET['id']);
  $query = "SELECT picture FROM `movies` WHERE id='$id'";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  header('Location: '. $row['picture']);
  exit;
?>

 

or, you need to use a PHP handler script to return the images....let me see if i can explain:

 

in your script, your JS would look like this:

<script language="JavaScript" type="text/javascript">
  function CngPicture(bilde){
    Movies = document.getElementById('movies');
    Index = Movies.selectedIndex;
    Value = Movies.options[index].value;
    document.getElementById('bilde').src = 'movieImage.php?id=' + Value;
  }
</script>

 

then, create a file called movieImage.php with the following code:

<?php
  //Put your MySQL Connection info here

  $id = mysql_real_escape_string($_GET['id']);
  $query = "SELECT picture FROM `movies` WHERE id='$id'";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  header('Location: '. $row['picture']);
  exit;
?>

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.