By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

Image popup from E-commerce store

P: 1
Hello All!

Having a bit of a problem combining php with javascript here. What I have is a store with images (There will be a smaller image of each item, and a larger image of each item, but I want users to click on a link under the image shown (Smaller image) for a popup window showing a larger image. I have already setup an additional table line named "image2" and want the image be puleed from the db (images folder) to pop up to a window that will default 20 pixels around the image.

Here is the script I placed in the head of the script:
PLEASE PUT YOUR CODE BETWEEN code TAGS NEXT TIME!!
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. <!-- //Hide from old browsers.
  3.  
  4. //Make a pop-up window function
  5. function create_window (image, width, height) {
  6.  
  7.     // Add some pixel dimensions here.
  8.     width = width + 20;
  9.     height = height + 40;
  10.  
  11.     // If the window is already open, resize it to the new dimensions.
  12.     if (window.popup_window && !window.popup_window.closed) {
  13.         window.popup_window.resizeTo (width, height);
  14.         }
  15.         //set the window properties
  16.         var window_specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes,
  17.         left=0, top=0, width=" + width + ", height=" + height;
  18.  
  19.         //Set the URL
  20.         var url = "image_window.php?image=" + image;
  21.  
  22.         //Create the pop-up window.
  23.         popup_window = window.open(url, "PictureWindow", window_specs);
  24.         popup_window.focus();
  25.  
  26. } //End of function
  27. //--></script>
  28.  
  29. OK, here is my php script on the store page:
  30.  
  31. <?php
  32.  
  33. require_once('mysql_connect.php');
  34. if (isset($_GET['page'])) {
  35.     $page = $_GET['page'];
  36. } else {
  37.     $page = 1;
  38. }
  39. $where = NULL;
  40. $link = NULL;
  41. $order = 'ItemID DESC';
  42.  
  43. if(isset($_GET['submit'])) {
  44.     $order = $_GET['order'];
  45.     if($_GET['category'] != '0') {
  46.         $category = $_GET['category'];
  47.         $where .= " AND CategoryID = '$category'";
  48.         $vlink = "$page&category=$category&order=$order&submit=Search";
  49.         $_SESSION['vlink'] = $vlink;
  50.         $link = "&category=$category&order=$order&submit=Search";
  51.     } else {
  52.         $vlink = "$page&category=0&order=$order&submit=Search";
  53.     }
  54.     $_SESSION['vlink'] = $vlink;
  55. }
  56. ?>
  57. <table border="0" width="587"><tr><td width="18">&nbsp;</td><td width="559">
  58. <form name="form1" method="get" action="">
  59.   <table width="500" height="29" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC" bordercolordark="#000000">
  60.     <tr> 
  61.       <td width="57" height="27" align="right" nowrap><font size="2">Category:</font></td>
  62.       <td width="140"><font size="2"> 
  63.         <select name="category">
  64.         <option value="0" selected>Choose a Category</option>
  65.         <?php
  66.         $u = NULL;
  67.         $qu = mysql_query("SELECT I.CategoryID, C.Name FROM Items I, Category C WHERE I.CategoryID = C.CategoryID AND I.InUse = 'Yes' ORDER BY I.CategoryID");
  68.         while($r = mysql_fetch_array($qu, MYSQL_NUM)) {
  69.             if($r[0] != $u) {
  70.                 echo "<option value='$r[0]'>$r[1]</option>";
  71.             }
  72.             $u = $r[0];
  73.         }
  74.         ?>
  75.         </select>
  76.         </font></td>
  77.       <td width="106" align="right" nowrap><font size="2">Order By:</font></td>
  78.       <td width="98" nowrap><font size="2"> 
  79.         <select name="order" id="select3">
  80.           <option value="Name" selected>Name</option>
  81.           <option value="Price">Price</option>
  82.         </select>
  83.         </font></td>
  84.       <td width="83" align="right" nowrap><input name="submit" type="submit" id="submit2" value="Search"></td>
  85.     </tr>
  86.   </table>
  87. </form>
  88. <?php
  89. $alt = 'first';
  90. $page = $page-1;
  91. $pag = $page*20;
  92. $q = mysql_query ("SELECT ItemID FROM Items WHERE InUse = 'Yes'$where ORDER BY $order");
  93. $query = mysql_query ("SELECT ItemID, Image, Name, Price, Sale, Description, Tax, Shipping, Image2, Inventory FROM Items WHERE InUse = 'Yes'$where ORDER BY $order LIMIT $pag, 20");
  94. $n = mysql_num_rows($q);
  95. $num = $n/20;
  96. $num = ceil($num);
  97. while($row = mysql_fetch_array($query, MYSQL_NUM)) {
  98.     echo "<table width='550' border='1' cellspacing='0' cellpadding='2' bgcolor='#EFEFEF' bordercolor='#000000'>
  99.               <tr> 
  100.                 <td width=80 rowspan='2'><img src='items/$row[1]' border=0>
  101.              <strong><font size='1' face='Arial, Helvetica, sans-serif'>             
  102.  
  103.  
  104.              <br> Click here for larger image. </br></font></strong>
  105.              </td>
  106.  
  107.                 <td><strong><font size='2' face='Arial, Helvetica, sans-serif'>Name: $row[2]</font></strong></td>";
  108.                if ($row[4] != 'No') {
  109.                   echo "<td><strong><font size='1' face='Arial, Helvetica, sans-serif' color='red'>Sale Price: $row[4]</font></strong></td>";
  110.               } else {
  111.                   echo "<td><strong><font size='1' face='Arial, Helvetica, sans-serif'>Price: $$row[3]</font></strong></td>";
  112.              }
  113.              echo "<td width=80 rowspan='2' align=center nowrap><a href='add_cart.php?pid=$row[0]'><font size='2' face='Arial, Helvetica, sans-serif'>Add to cart</font></a></td>
  114.              </tr>
  115.               <tr> 
  116.                 <td colspan='2' valign=top><font size='1' face='Arial, Helvetica, sans-serif'><strong>Description: $row[5]
  117.               </strong></font></td>
  118.               </tr>
  119.         </table><br>";
  120. }
  121. echo "<font size=2>&lt;&lt;Prev ";
  122. $a = 0;
  123. while ($a < $num) {
  124.     $a++;
  125.     echo "<a href='index.php?page=$a$link'>$a</a>";
  126.     if ($a != $num) {
  127.         echo " - ";
  128.     }
  129. }
  130. echo " Next&gt;&gt;</font>";
  131.  
  132. //<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  133. //<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
  134. //<input type="hidden" name="add" value="1">
  135. //<input type="hidden" name="cmd" value="_cart">
  136. //<input type="hidden" name="business" value="johnny@anywhere.com">
  137. //<input type="hidden" name="item_name" value="ItemName">
  138. //<input type="hidden" name="item_number" value="ItemID">
  139. //<input type="hidden" name="amount" value="1.00">
  140. //<input type="hidden" name="no_note" value="1">
  141. //<input type="hidden" name="currency_code" value="USD">
  142. //<input type="hidden" name="lc" value="US">
  143. //<input type="hidden" name="bn" value="PP-ShopCartBF">
  144. //</form>
  145. ?>
  146.  
PLEASE PUT YOUR CODE BETWEEN [code] TAGS NEXT TIME!!

Any suggestions would be greatly appreciated! Thanks...
Oct 6 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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