Jump to content

[SOLVED] Dynamically changing pop up details


Yaheed

Recommended Posts

On the website I'm working on (http://www.robinsongroup.com.au, I've made a list of products that is displayed by outputting my mysql database table with all the information I need in it.

 

The field names of the table within my database, 'barstools', is productID, thumbLink, picLink, printLink, sizeDepth, sizeWidth, sizeHeight, seatHeight, and prodDesc which correspond to the name of the product, the link to the thumbnail image, link to the larger image, link to the print pop-up page, and various size and desription information respectively. You can see what it outputs as at http://www.robinsongroup.com.au/barstools.php

 

Now what I want to do is when someone clicks on the printer icon, a pop-up appears with printable information on the particular product they have selected. I have no problems with doing this if I create a html page for every single product on the site (which will be reaching the thousands possibley) and link it to each print icon respectively. Now I don't want to make a thousand html pages and change the image of every single page and information individually.

 

Is there a way that I can use the variables I have used to make the list and make the print link and details correspond to the product they have selected, such as a print.php page?

 

Code of barstools.php

<script type="text/javascript">
<!--//js for onclick function
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>

<?php	
$query = "SELECT * FROM barstools";

$result = mysql_query($query,$cxn);

// Display results in a table
echo "
<table>\n";
echo "<tr class='tableHeader'>\n";
echo "<td>Click for a larger image</td>\n";
echo "<td> </td>\n";
echo "<td>product ID</td>\n";
echo "<td>depth (mm)</td>\n";
echo "<td>width (mm)</td>\n";
echo "<td>height (mm)</td>\n";
echo "<td>seat height (mm)</td>\n";
echo "<td>description</td>\n";
echo "</tr>\n";
echo "<tr><td colspan='8'><hr></hr></td></tr>\n";

while ($row = mysql_fetch_assoc($result))
{
	extract($row);
	echo "<tr>\n
	<td><a href='$picLink' rel=\"lightbox\" title='$prodDesc'><img src='$thumbLink' alt='$productID' width='120px' height='120px' /></a></td>\n
	<td><img src='/images/siteImages/printIcon.png' alt='Print' onclick=\"MM_openBrWindow('$printLink','Print','width=250,height=350')\" /></td>\n
	<td>$productID</td>\n
	<td>$sizeDepth</td>\n
	<td>$sizeWidth</td>\n
	<td>$sizeHeight</td>\n
	<td>$seatHeight</td>\n
	<td class='description'>$prodDesc</td>\n
	</tr>\n";
	echo "<tr><td colspan='8'><hr></hr></td></tr>\n";
};
echo "</table>\n";
?>

 

 

Link to comment
Share on other sites

You simply create a link and include the primary key of the product you want to show on the page.

 

Let's say your the new script you'll create is called print.php and it will accept a GET value that is the key to the product.

 

i.e.   ... href='print.php?id=$productID' ...

 

Then in print.php grab the value passed (I assume the ID value will be an integer):

 

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

 

Then you use that ($id) to retrieve the product data from the table and format the output any way you want.

 

hth.

 

 

 

Link to comment
Share on other sites

Thanks for that code, helped heaps.

 

So far I've come up with this:

 

within the barstools.php page, I have on the print image:

 

<?php
<td><img src='/images/siteImages/printIcon.png' alt='Print' onclick=\"MM_openBrWindow('print.php?id=$productID&pic=$thumbLink','','width=250,height=350')\" /></td>\n
?>

 

The key code being print.php?id=$productID&pic=$thumbLink'"

 

print.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
$id = isset($_GET['id']) ? strval($_GET['id']) : 0;
$pic = isset($_GET['pic']) ? strval($_GET['pic']) : 0;

echo "<title>Print $id</title>";
?>

</head>

<body>

<?php
echo "$id\n";
echo "<img  src=\"$pic\" width='120px' height='120px' alt='$id' />";
?>

</body>
</html>

 

And they output just fine. Is this what you meant or is there a more efficient way of doing it?

 

You have greatly solved me a lot of work  :-*;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.