views:

60

answers:

2

i used javascript and php script as mixed. i got a parse error

this is the code

<script language="JavaScript1.1">
var photos=new Array()
var which=0


 <? for($i=0;$i< count($productdata2);$i++)
 {
 foreach($productdata2 as $row)
  {?>
   // the error occured at this line

  photos[0]=<?=base_url().'uploads/'.$productdata2[$i]->image;?>";

   // the error occured at this line
  <? }
  }
  ?>


  function backward(){
  if (which>0){
  window.status=''
  which--
  document.images.photoslider.src=photos[which]
  }
  }

  function forward(){
  if (which<photos.length-1){
  which++
  document.images.photoslider.src=photos[which]
  }
  else window.status='End of gallery'
  }
  </script>

help me please.....

+3  A: 

There is a missing $ in front of photos which causes the Parse error

photos[$i] should be $photos[$i]

Apart from that, you've made a function call inside a string:

$photos[$i]="base_url().'uploads/'.$productdata2[$i]->image";

should be:

$photos[$i]=base_url().'uploads/'.$productdata2[$i]->image;
codaddict
A: 

The " at the end of

photos[0]=<?=base_url().'uploads/'.$productdata2[$i]->image;?>";

is wrong. And I think mixing JavaScript and PHP renders the code unreadable. This might be a case for AJAX.

Anonymous Coward