Jump to content

[SOLVED] PHP/Javascript pop up window


Northern Flame

Recommended Posts

I am designing a website for a photographer

and on the template i have a section that

shows his newest photos. The information

of these photos is stored in a MySQL

database with the columns,

 

name

src (Image Source ex: http://site.com/images/pic.jpg)

id

 

when a user clicks on an image i want

a pop up window to apear with the image

clicked on

 

i know how to do this using javascript,

<head>
<script type="text/javascript">
<!--
function myPopup() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, height = 300, width = 300, resizable = 0" )
}
//-->
</script>
</head>
<body>
<img onClick="myPopup()" src="/images/pic.jpg">
</body>

 

but how can i do add that into my script

 

<?php
    $host = 'localhost';
$user = 'user';
$pass = 'pass';
$db = 'db';

@mysql_connect($host, $user, $pass) or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db($db) or die("ERROR--CAN'T CONNECT TO DB");

$limit = 4;
$query_count = "SELECT count(*) FROM ringtones";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

$query = "SELECT * FROM ringtones ORDER BY id DESC LIMIT $limit";
$result = mysql_query($query) or die("ERROR " . mysql_error());
        echo '<div id="gallery">
    while($row = mysql_fetch_array($result)){
echo '<div class="gal"><img title="'.$row["name"].'" src="'.$row["src"].'"></div>';
}
mysql_free_result($result);

?>

 

i know all i have to do is

echo the details of the function,

<script type="text/javascript">
<!--
function myPopup() {
window.open( "http://www.google.com/", "myWindow", 
"status = 1, height = 300, width = 300, resizable = 0" )
}
//-->
</script>

 

and then just add this to the image, onClick="myPopup()",

but how can i get the url, "http://www.google.com",

to change to the image i want opened?

Link to comment
https://forums.phpfreaks.com/topic/65344-solved-phpjavascript-pop-up-window/
Share on other sites

Why using a function?

 

This is something I used which is what you may be looking for:

<a href='#' onClick='window.open("smilies.php", "smileys", "resize=0, toolbar=0, menubar=0, resizeable=0, width=250, height=500");'>Smilies</a>

 

Here's one for an image you would have at the end of your coding:

echo '<div id="gallery">
    while($row = mysql_fetch_array($result)){
echo '<div class="gal"><img title="'.$row["name"].'" src="'.$row["src"].'" onClick=\'window.open("FILENAME", "image_preview", "resize=0, toolbar=0, menubar=0, resizeable=0, width=250, height=500");\'></div>';
    }

 

You should customize it, but yeah.

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.