Jump to content

[SOLVED] php foreach combined with javasvript function


Lodius2000

Recommended Posts

Hi, ive got a js function inside php foreach and it isnt doing the right thing

 

<?php
foreach($thumbs as $thumb){
	$url = $db->getOne('SELECT thumb_url FROM image WHERE id = ?', array($thumb));
	print '<div class="img">';
	print ("<script type=\"text/javascript\">\nfunction uploadwindow() {
new_window = window.open('../editcaption/index.php?id=" . $thumb . "','popup','width=650,height=440,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
}
</script>
</script>
<a href=\"javascript:uploadwindow();\">" . $url . "</a>");
	print '<div class="desc">Image '.$thumb.'</div></div>';
}
?>

 

it is an image gallery that when you click an image the caption comes up in a popup, so you can edit it

 

now the problem is that the portion that says

window.open('../editcaption/index.php?id=" . $thumb . "','popup','

the $thumb always points to the last $thumb in the foreach loop, no matter which of the images that you click on the frontend side you click to open the popup.

 

I checked the page source and each of the urls in the separate js functions do point to the right iteration of $thumb, but like i said when clicked they all go to the last $thumb

 

Thanks for the help

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.