i m a beginner in Php. Please help me to open link in new window. code is

<?php 

require("connect.php");

$album =mysql_query("SELECT * FROM albums");

echo "<table width='22%'>";
while ($row = mysql_fetch_assoc($album))
{
	echo "
	<tr>
	   <td>
	      <img src='images/".$row['cover']."' width='100%' height='100%'>
	   </td>
	   <td>
	      <b>".$row['name']."</b><br>
	      ".$row['description']."
	   </td>
	</tr>
	

	";
}
echo "</table>";

?>

How can i display an image in new window when click on Thumbnail.

Recommended Answers

All 7 Replies

Replace your line <img src...> with

<a href=\"images/".$row['cover']"\" onclick=\"newWindow('images/".$row['cover'].'");\" return false;\"><img src=\"image/".$row['cover']."\"></a>

The image is still displayed and when clicked, a small piece of javascript will open a new windows and display the image again.

If you don't want to display the image again replace the <a href with the actual page that needs to be loaded, like <a href="target.php"...

First of all thank you for helping me. When i replace the code given by you an error occurring

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\xampp\Create album\pagination1.php on line 45

When i replace <img src.... with this code then my script is working but when i click on image then new teb open not new window. This is my code...

<a href=\"images/big/".$row['cover']."\" onclick=\"newWindow('images/big/".$row['cover']."\" 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=670, height=800';'\" return false;\" target='_blank'><img src='images/".$row['cover']."' border='0' width='100%' height='100%'></a>

well considering there arent 35 lines, repost your edited code, so one of the gurus can have an AHA moment
its likely simple, a mismatched set of quotes, but hard to diagnose from an errormessage that has more lines than the code sample

When i replace <img src.... with this code then my script is working but when i click on image then new teb open not new window. This is my code...

<a href=\"images/big/".$row['cover']."\" onclick=\"newWindow('images/big/".$row['cover']."\" 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=670, height=800';'\" return false;\" target='_blank'><img src='images/".$row['cover']."' border='0' width='100%' height='100%'></a>

To get this kind of code working ... There are to many " and ' that can make it go wrong and in the end you don't see anymore what is going on. So in the following 3 steps, I start with normal html code, rewrite it to php and finally insert the variable. The code is tested and works.

<!-- The normal html code -->
<a href="/images/cover.jpg"
   onclick="window.open (this.href, 'child', 'toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=yes,width=670,height=800'); return false">
	<img alt="CoverImage" src="/images/cover.jpg">
</a>

<?php
// Translated to php 
echo "<a href=\"/images/cover.jpg\"
	onclick=\"window.open (this.href, 'child', 'toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=yes,width=670,height=800'); return false\">
	<img alt=\"CoverImage\" scr=\"/images/cover.jpg\">
      </a>";


// The variable added
echo "<a href=\"/images/".$row['cover']."\"
	onclick=\"window.open (this.href, 'child', 'toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=no,scrollbars=yes,width=670,height=800'); return false\">
	<img alt=\"CoverImage\" scr=\"/images/".$row['cover']."\">
     </a>";
?>

Thank you colweb. you solved this :)

Thank you colweb. you solved this :)

Nice to know. Could you please mark this thread as solved? Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.