473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need to show the larger image when user clicks on the small image

hello,

Can any one please tell me

I am Using php,Mysql,CSS to build my site

In my database i have small images and large images
i am show the small images to the right of the main container now i need to show the large image to left side when user clicks on these small images
but when i click on the images it is showing the large image in the new browser

hope u understand my problem
please tell me what wrong am i doing

here is my code


Expand|Select|Wrap|Line Numbers
  1.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  <html xmlns="http://www.w3.org/1999/xhtml">
  3.  <head>
  4.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.  <title>Untitled Document</title>                                        
  6.  
  7.  <style type="text/css">
  8.  #container
  9.  {
  10.      float:left;
  11.      border:5px solid #666;  
  12.      position:relative; 
  13.      width:770px; 
  14.      height:450px; 
  15.      margin:20px auto 0 100px;
  16.      top:-20px;
  17.  }
  18.  
  19.  .styles
  20.  {
  21.      text-align:center;
  22.      margin:190px 390px 0px 20px;    
  23.  }
  24.  #container1
  25.  {
  26.      float:right;
  27.      border:1px solid #9F0;
  28.      padding:3px;
  29.      height:445px; 
  30.      width:355px;
  31.      margin:-250px 0px 0px 0px;
  32.  }
  33.  .yourstyle
  34.  {
  35.  position:absolute;
  36.  left:0px;
  37.  top:-2px;
  38.  
  39.  }
  40.  
  41.  
  42.  </style>            
  43.  
  44.  </head>
  45.  
  46.  <?php
  47.             function connect()
  48.             {
  49.                $dbhost='aaa';
  50.                $dbuser='aa';
  51.                $dbpass='aaa';
  52.                $conn= mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'.mysql_error());
  53.                $dbname='hakman';
  54.                mysql_select_db($dbname);
  55.                return $conn;
  56.             }
  57.  ?>
  58.  
  59.  <body bgcolor="#0a1936" >
  60.  
  61.  <div id="container">
  62.  
  63.  <p class="styles"><font color="#FFFFFF" face="Monotype Corsiva" size="+2">
  64.  
  65.  Image should be shown here when user clicks
  66.  
  67.  </font></p>
  68.  
  69.  
  70.  
  71.  
  72.  <?php 
  73.  $c=connect(); 
  74.  $query2="select style from styles"; 
  75.  $sql=mysql_query($query2); 
  76.  $result2=mysql_num_rows($sql);  //25
  77.  
  78.  $query="select path from styles "; //0 to 6
  79.  $result=mysql_query($query);                                    
  80.  
  81.  $query1="select big_img from styles "; //0 to 6
  82.  $result1=mysql_query($query1);                                    
  83.  
  84.  $query3="select style,path from styles ";
  85.  $result3=mysql_query($query3); 
  86.  
  87.  ?>
  88.       <div id="container1">
  89.                  <?php
  90.                          echo '<table border="1" align="right" width="50px" height="375px" BORDERCOLOR="#9F0">'; 
  91.                          for($r=1;$r<=4;$r++) 
  92.                          { 
  93.                              echo '<tr>'; 
  94.                              for($d=1;$d<=2;$d++) 
  95.                              { 
  96.                                   $obj=mysql_fetch_object($result);
  97.                                   $obj1=mysql_fetch_object($result1);
  98.                                   $obj2=mysql_fetch_object($sql);    
  99.                                   $obj3=mysql_fetch_object($result3);
  100.                                   $imageSrc=$obj->path; 
  101.                                   $cimage="/images/".$obj->path; 
  102.                                   $big="/images/".$obj1->big_img; 
  103.                                   $styl=$obj3->style; 
  104.                                   $sty2=$obj3->style; 
  105.  
  106.              echo '<td><a title="'.$styl.'" href="'.$big.'" id="'.trim($sty2).'"><img width="170px" height="100px" src=" ' . $cimage . ' " /></a></td>'; 
  107.  
  108.                   ?>       
  109.        </div>            
  110.         <div class="yourstyle" id="<?php echo trim($sty2).'-big'?>"></div>     
  111.  
  112.                   <?php 
  113.  
  114.  
  115.        }       
  116.        echo '</tr>';
  117.      } 
  118.  echo'</table>';?>
  119.  
  120.    </div>
  121.  
  122.    ?>       
  123.  
  124. </body>
  125.  </html>
  126.  
Dec 20 '08 #1
3 2490
Markus
6,050 Expert 4TB
Hi, swetha123, and welcome to the forums.

It is a requirement that, when posting code in your post, you wrap it with [code] ... [/code] tags. This helps our experts read your code as it is formatted. This, in turn, then helps our experts with answering your question. In future, please follow this guideline. You can find other guidelines here - please take a second to read over them, so you can avoid any warnings in the future.

Thanks,
Moderator.
Dec 20 '08 #2
Markus
6,050 Expert 4TB
Let me just say Javascript would be a much more efficient way of doing this.

Why is your image opening as a new page?

That's because you provide a link to the image in the form of <a href="...">. Of course, if the user clicks this, they will be taken to the image's location.

How about, instead of passing the image's location in your href attribute, you pass an identifier for the image to the current URL. That way you can get the ID using $_GET and then use that for the large image's src attribute.

Again, I suggest using Javascript, though.

Thanks,
Markus.
Dec 20 '08 #3
hsriat
1,654 Expert 1GB
Change line 106:
Expand|Select|Wrap|Line Numbers
  1. echo '<td><a title="'.$styl.'" href="#bigImage" onclick="this.parentNode.getElementsByTagName('img')[0].src=\''.$big.'\'; return false;" id="'.trim($sty2).'"><img src=" ' . $cimage . ' " /></a></td>';
Dec 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
2
by: Stevio | last post by:
In my web page I preload images so that when a user clicks on a part of the image, the image changes. The images are used to display 4 tabs. Each image shows a different tab as highlighted. If a...
1
by: jdapro | last post by:
Hi - thanks for reading this out there! I'll be quick about it: I've got this row of images (in the end there will be more rows of pics as well). When a user clicks on the image, I want a new...
8
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta)...
2
by: Beemer Biker | last post by:
I have a 10 row (per page) gridview where the first column is a small image under 100x200px and the second column is a DropDownList template that selects which image to show in the first column. ...
4
by: =?Utf-8?B?Tm9ibGUgQmVsbA==?= | last post by:
Hello, I want to know how I can do the following in ASP.Net 2.0: I want to be able to mouse-over a small image and then have it dynamically zoom into a larger image. When the larger image is...
1
by: swetha123 | last post by:
hello, Can any one please tell me I am Using php,Mysql,CSS to build my site In my database i have small images and large images i am show the small images to the right of the main container...
0
by: zeckdude | last post by:
Hi, I am having some issues with my site. I have a main Nav with four links that load in 4 different sections. You can see the page I am working on here:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.