Jump to content

A little help needed with simple problem: pop-up image


jw_d

Recommended Posts

I'd really appreciate any help someone could lend... I've tried 100 different ways to make this happen, but keeping getting screwed up.

 

I have a script which shows small images. What I want to do is for the user to click the photo and it enlarge in a pop-up screen. The page already exist for it to pop up in (view_image.php), but I just can't get it to open that window.

 

Here's the code:

<?php
$sql="select image from inputinfo where id='$id'";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
if($row['image']=="" && $row['image']=="") {}else{
echo "<img src='admin/{$row['image']}' width='100' height='60' border='1' />";
}
?>

 

Here's where I tried to modify it and script stalls out (I inserted the onclick):

<?php
$sql="select image from inputinfo where id='$id'";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
if($row['image']=="" && $row['image']=="") {}else{
echo "<img src='admin/{$row['image']}' width='100' height='60' border='1' 

onclick="window.open('view_image.php?id=<? echo $id;?>','mywindow','menubar=1,resizable=1,width=550,height=550')"

/>";
}
?>

 

Thanks SO MUCH for any help!

I went in there and added the quote, but the page still loads blank... I'm using IE and no js errors show.

 

Here's what I changed it to:

 

<?php
$sql="select image from inputinfo where id='$id'";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
if($row['image']=="" && $row['image']=="") {}else{
echo "<img src='admin/{$row['image']}' width='100' height='60' border='1' 

onclick="window.open('view_image.php?id=<? echo $id;?>','mywindow','menubar=1,resizable=1,width=550,height=550')"

/>";
}
?>

 

EDIT: Not sure why... the single quote ' is there before view_image but not displaying on here for some reason

You're right, i can see the quote in the source of your post but not when it's displayed .. maybe a bug in phpfreaks.

 

The code looks ok to me .. one approach you could try is finding a website that successfully pops up a window for you, and copying their code (or examining it to see how it differs from yours)

may i suggest lightbox

 

its a javascript cross browser compatible thing,

it doesnt open in a "new window" so it is not screwed over by popup blockers, but it appears clearly.

its used successfully on many large sites and is becoming sort of a standard,

 

but as an example

 

heres trademe (new zealands version of ebay) they use it,

 

click on one of the pictures to see what i mean

 

ps this is just some random auction

 

http://www.trademe.co.nz/Antiques-collectables/Alcohol-related/Beer-related/Other/auction-201359308.htm

 

since the image is available in browser already with some size

 

use javascript

 

take the image from dom

to chanage the css 

present in a layer

 

which is basically what lightbox does for you in a tidy manor ;)

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.