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
- <script language="javascript">
- <!-- //Hide from old browsers.
- //Make a pop-up window function
- function create_window (image, width, height) {
- // Add some pixel dimensions here.
- width = width + 20;
- height = height + 40;
- // If the window is already open, resize it to the new dimensions.
- if (window.popup_window && !window.popup_window.closed) {
- window.popup_window.resizeTo (width, height);
- }
- //set the window properties
- var window_specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes,
- left=0, top=0, width=" + width + ", height=" + height;
- //Set the URL
- var url = "image_window.php?image=" + image;
- //Create the pop-up window.
- popup_window = window.open(url, "PictureWindow", window_specs);
- popup_window.focus();
- } //End of function
- //--></script>
- OK, here is my php script on the store page:
- <?php
- require_once('mysql_connect.php');
- if (isset($_GET['page'])) {
- $page = $_GET['page'];
- } else {
- $page = 1;
- }
- $where = NULL;
- $link = NULL;
- $order = 'ItemID DESC';
- if(isset($_GET['submit'])) {
- $order = $_GET['order'];
- if($_GET['category'] != '0') {
- $category = $_GET['category'];
- $where .= " AND CategoryID = '$category'";
- $vlink = "$page&category=$category&order=$order&submit=Search";
- $_SESSION['vlink'] = $vlink;
- $link = "&category=$category&order=$order&submit=Search";
- } else {
- $vlink = "$page&category=0&order=$order&submit=Search";
- }
- $_SESSION['vlink'] = $vlink;
- }
- ?>
- <table border="0" width="587"><tr><td width="18"> </td><td width="559">
- <form name="form1" method="get" action="">
- <table width="500" height="29" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC" bordercolordark="#000000">
- <tr>
- <td width="57" height="27" align="right" nowrap><font size="2">Category:</font></td>
- <td width="140"><font size="2">
- <select name="category">
- <option value="0" selected>Choose a Category</option>
- <?php
- $u = NULL;
- $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");
- while($r = mysql_fetch_array($qu, MYSQL_NUM)) {
- if($r[0] != $u) {
- echo "<option value='$r[0]'>$r[1]</option>";
- }
- $u = $r[0];
- }
- ?>
- </select>
- </font></td>
- <td width="106" align="right" nowrap><font size="2">Order By:</font></td>
- <td width="98" nowrap><font size="2">
- <select name="order" id="select3">
- <option value="Name" selected>Name</option>
- <option value="Price">Price</option>
- </select>
- </font></td>
- <td width="83" align="right" nowrap><input name="submit" type="submit" id="submit2" value="Search"></td>
- </tr>
- </table>
- </form>
- <?php
- $alt = 'first';
- $page = $page-1;
- $pag = $page*20;
- $q = mysql_query ("SELECT ItemID FROM Items WHERE InUse = 'Yes'$where ORDER BY $order");
- $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");
- $n = mysql_num_rows($q);
- $num = $n/20;
- $num = ceil($num);
- while($row = mysql_fetch_array($query, MYSQL_NUM)) {
- echo "<table width='550' border='1' cellspacing='0' cellpadding='2' bgcolor='#EFEFEF' bordercolor='#000000'>
- <tr>
- <td width=80 rowspan='2'><img src='items/$row[1]' border=0>
- <strong><font size='1' face='Arial, Helvetica, sans-serif'>
- <br> Click here for larger image. </br></font></strong>
- </td>
- <td><strong><font size='2' face='Arial, Helvetica, sans-serif'>Name: $row[2]</font></strong></td>";
- if ($row[4] != 'No') {
- echo "<td><strong><font size='1' face='Arial, Helvetica, sans-serif' color='red'>Sale Price: $row[4]</font></strong></td>";
- } else {
- echo "<td><strong><font size='1' face='Arial, Helvetica, sans-serif'>Price: $$row[3]</font></strong></td>";
- }
- 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>
- </tr>
- <tr>
- <td colspan='2' valign=top><font size='1' face='Arial, Helvetica, sans-serif'><strong>Description: $row[5]
- </strong></font></td>
- </tr>
- </table><br>";
- }
- echo "<font size=2><<Prev ";
- $a = 0;
- while ($a < $num) {
- $a++;
- echo "<a href='index.php?page=$a$link'>$a</a>";
- if ($a != $num) {
- echo " - ";
- }
- }
- echo " Next>></font>";
- //<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
- //<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!">
- //<input type="hidden" name="add" value="1">
- //<input type="hidden" name="cmd" value="_cart">
- //<input type="hidden" name="business" value="johnny@anywhere.com">
- //<input type="hidden" name="item_name" value="ItemName">
- //<input type="hidden" name="item_number" value="ItemID">
- //<input type="hidden" name="amount" value="1.00">
- //<input type="hidden" name="no_note" value="1">
- //<input type="hidden" name="currency_code" value="USD">
- //<input type="hidden" name="lc" value="US">
- //<input type="hidden" name="bn" value="PP-ShopCartBF">
- //</form>
- ?>
Any suggestions would be greatly appreciated! Thanks...