Schlo_50 Posted January 31, 2007 Share Posted January 31, 2007 I am trying to build a commerce website.I have items displayed on a page, all linked from a database. What i want to happen is have the ability to enable customers to click on one of the items to get a page up for that item alone. Can i do this by creating one page and adding code so that what ever item is clicked it will display on it instead of having one page per item displayed on the site?If it is possible to create one new page and add the code can someone point me in the right direction of obtaining it?Sorry if thats complicated to understand, i'll try to re-explain if so.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/ Share on other sites More sharing options...
HuggieBear Posted January 31, 2007 Share Posted January 31, 2007 Sure, so create an item_detail.php and pass it the id of the product in the URL, through an html link that looks something like this:[code=php:0]<a href="item_detail.php?product_id=29">View Details</a>[/code][b]item_detail.php[/b][code]<?php// Get the id from the URL$id = $_GET['product_id'];// Query the database for the details$sql = "SELECT * FROM details WHERE id_column = '" . $id . "'";$result = mysql_query($sql) or die ("Unable to execute $sql: " . mysql_error())$details = mysql_fetch_array($result, MYSQL_ASSOC);// Echo the results, these will differ depending on the ID passed to the pageecho "Product ID: " . $details['id_column'];echo "Product Name: " . $details['name'];echo "Product Decription: " . $details['short_desc'];?>[/code]Get the idea?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-173599 Share on other sites More sharing options...
Schlo_50 Posted February 1, 2007 Author Share Posted February 1, 2007 Thanks, I get the picture. Ta' ;) Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-174639 Share on other sites More sharing options...
Schlo_50 Posted March 12, 2007 Author Share Posted March 12, 2007 Here is my item_detail.php file, which i think is correct: <?php // Get the id from the URL $id = $_GET['st_id']; $conn = mysql_connect( "host","username","password" ) $rs = mysql_select_db( "dombar0_work") or die( "Err:Db" ); or die( "Err:Conn" ); // Query the database for the details $sql = "SELECT * FROM stock_tbl WHERE st_id = '" . $id . "'"; $result = mysql_query($sql) or die ("Unable to execute $sql: " . mysql_error()) $details = mysql_fetch_array($result, MYSQL_ASSOC); // Echo the results, these will differ depending on the ID passed to the page echo "Product ID: " . $details['st_id']; echo "Product Name: " . $details['name']; echo "Enlarged Image: " . $details['image']; echo "Product Decription: " . $details['descr']; echo "Price: " . $details['price']; ?> I then have this script which displays items on my page, but the only problem is i have no idea where to enter that html link.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Davison Jewellery</title> <link href="http://dombar0.freehostia.com/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div align="center"> <table width="696" height="610" border="1" align="center" bordercolor="#18501F"> <tr> <th colspan="2" scope="col"><p><img src="http://img48.imageshack.us/img48/5879/banner1qe6.jpg" width="688" height="88" /></th> </tr> <tr> <th width="140" height="514" scope="col"><div align="right" class="style1"><span class="style3"> <table width="138" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="138" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="http://img518.imageshack.us/img518/34/headeres7.jpg" width="138" height="47"></td> </tr> <tr> <td background="http://img73.imageshack.us/img73/1869/middiy5.jpg"><table width="100" height="425" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><p align="center"><a href="http://dombar0.freehostia.com/newjewl.php">New Jewellery</a> </p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/antiq.php">Antique Jewellery</a> </p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/preown.php">Pre-Owned Jewellery</a></p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/mais.php">Maisonic Jewellery</a> </p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/rings.php">Rings</a> </p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/silgif.php">Silver/Giftware</a> </p> <p align="center"> </p> <p align="center"><a href="http://dombar0.freehostia.com/misc.php">Miscellaneous</a></p></td> </tr> </table> <div align="right"></div></td> </tr> <tr> <td><img src="http://img523.imageshack.us/img523/4605/bottomkw6.jpg" width="138" height="23"></td> </tr> </table></td> </tr> </table> </td> <td width="550" scope="col"><div> <div align="left"> <?php $host = 'mysql2.freehostia.com' ; $user = 'username' ; $pass = 'password' ; $db = 'dbname' ; $table = 'tablename' ; $show_all = 'SELECT * FROM stock_tbl' ; mysql_connect ($host,$user,$pass) or die ( mysql_error ()); mysql_select_db ($db)or die ( mysql_error ()); $result = mysql_query ($show_all) or die ( mysql_error ()); while ($row = mysql_fetch_array ($result)) { echo $row['st_id']. ' - <img src="'. $row['image'] . '" />' . $row['descr'] . ' - ' . $row['price'] . "<br />\n"; } ?> </div> </div> </tr> </table> <p></th> </tr> </table> </p> <blockquote><blockquote><blockquote> </blockquote> </blockquote> </blockquote> <p class="style4">Copyright 2006/7</p> <p class="style4">Created by Dominic Barnard </p> </div> </body> </html> <a href="home.php"></a> </body> </html> Please help Huggie! (or somebody) lol Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-205446 Share on other sites More sharing options...
boo_lolly Posted March 12, 2007 Share Posted March 12, 2007 what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-205491 Share on other sites More sharing options...
Schlo_50 Posted March 13, 2007 Author Share Posted March 13, 2007 Read my first post about what i want to end up with. I now have an item_detail.php file although i don't know how and where to insert the link to that file so that when an item is clicked it calls the item_detail.php file and displays the specific item details and it's enlarged picture. Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-206107 Share on other sites More sharing options...
boo_lolly Posted March 13, 2007 Share Posted March 13, 2007 something like this: <?php //browse_items.php $path = "/home/www/items/images/"; $sql = "SELECT * FROM your_items_table"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ echo "<img src=\"". $path . $row['image'] ."\" height=\"250\" width=\"250\">\n"; echo "<a href=\"javascript:void(0)\" onclick=\"window.open('popup.php?itemID\". $row['id'] ."','popup.php','width=630,height=700,scrollbars=yes')\"><u>Click to view item</u></a><br />\n"; } ?> <?php //popup.php $path = "/home/www/items/images/"; $sql = "SELECT * FROM your_items_table WHERE id = ". $_GET['itemID'] .""; $query = mysql_query($sql)l while($row = mysql_fetch_array($query)){ echo "Item: ". $row['name'] ."<br />\n"; echo "<img src=\"". $path . $row['image'] ."\"><br />\n"; echo "Price: ". $row['price'] ."\n"; } ?> between mine and huggie's post, you should get the general idea. Quote Link to comment https://forums.phpfreaks.com/topic/36474-item-display/#findComment-206217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.