Lodius2000 Posted November 24, 2008 Share Posted November 24, 2008 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 Link to comment https://forums.phpfreaks.com/topic/133981-solved-php-foreach-combined-with-javasvript-function/ Share on other sites More sharing options...
Lodius2000 Posted November 24, 2008 Author Share Posted November 24, 2008 concatinate $thumb onto the end of both the js fucntion definition and the call to the js function I love epiphanies on the way home from work SOLVED Link to comment https://forums.phpfreaks.com/topic/133981-solved-php-foreach-combined-with-javasvript-function/#findComment-697459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.