daniel5455 Posted August 31, 2008 Share Posted August 31, 2008 I have a webpage that shows a list of items that pulls from a mysql db. I am trying to set it up where when a person clicks on the image next to the item it will open a new page with just that item on it and all the info from the db pertaining to that item. What is the correct mysql query statment? $result = mysql_query("select * from product where id=???); i want it to know the id from the image i click. I linked the image with this code. <a href="./productsdetail.php?id=<?php echo $row['id'];?>" ><img src= "productimages/<?php echo $row['image']; ?>" width="100" height="100" border="0"></a> thanks in advanced Link to comment https://forums.phpfreaks.com/topic/122067-trying-to-pull-information-from-a-mysql-db/ Share on other sites More sharing options...
cooldude832 Posted August 31, 2008 Share Posted August 31, 2008 Well you are setting the id to be $_GET['id'] so your query should be similar to <?php $q = "Select * from `products` where id = '".mysql_real_escape_string($_GET['id'])."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> Link to comment https://forums.phpfreaks.com/topic/122067-trying-to-pull-information-from-a-mysql-db/#findComment-630144 Share on other sites More sharing options...
dropfaith Posted August 31, 2008 Share Posted August 31, 2008 $Id = mysql_escape_string($_GET['Id']); $query = "SELECT * FROM blog WHERE Id = '$Id'"; <a href="./productsdetail.php?id=<?php echo $row['id'];?>" ><img src= "productimages/<?php echo $row['image']; ?>" width="100" height="100" border="0"></a> Link to comment https://forums.phpfreaks.com/topic/122067-trying-to-pull-information-from-a-mysql-db/#findComment-630151 Share on other sites More sharing options...
daniel5455 Posted August 31, 2008 Author Share Posted August 31, 2008 Here is the entire page code. It does not populate the data to the page. <?php session_start();?> <?php require_once($_SERVER[DOCUMENT_ROOT] . "/includes/config.php"); ?> <?php require_once($_SERVER[DOCUMENT_ROOT] . "/includes/maketitle.php"); ?> <?php if($_GET['id'] != null) { $r = mysql_query("select image from product where id=".$_GET['id']); if($ro = mysql_fetch_array($r)) { if(is_file($ro['image'])) unlink('productimages//'.$ro['image']); } mysql_query("delete from product where id=".$_GET['id']); } $result = "Select * from `product` where id = '".mysql_real_escape_string($_GET['id'])."'"; $r = mysql_query($result) or die(mysql_error()."<br /><br />".$result) ?> <!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>Products</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> 6 </head> <body> <div id="main"> <div id="logo"><a href="index.php"><img src="images/logo.gif" alt="test." border="0" style="display:block;float:left;" /></a> <?php if (!(isset($_SESSION["userid"]))) { echo '<span style="font-size: 11px; color: #000000; font-family: Tahoma, Verdana"><span lang="en-us"><font size="2" color="#EF5494">* </font> <a href="register.php"><font size="2" color="#EF5494">Create Account!</font></a></span> '; echo '<a href="login.php"><strong>Login</strong></a>'; } else { echo '<a href="changepassword.php">Change Password</a> '; echo '<a href="logout.php"><strong>Logout</strong></a>'; } ?> <?php require_once("_nav.php"); ?> </div> <div id="mainphoto"><img src="images/banner.jpg" alt="test"></a></div> <div class="clear"></div> <div id="main-inner"> <div id="main-inner-left"> <h1>Products</h1> <br /> <table 4 width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td> <table 5 border="0" cellpadding="0" cellspacing="0" width="100%" height="85%"> <tr> <td valign=top align=left height=100%> <br> <table 6 width="145" height="137" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td ><center> <a href=''><font color=#046380 size=2><u></u></font></a> <a target='new'><img src= "productimages/<?php echo $row['image']; ?>" width="100" height="100" border="0"></a> </center></td> </tr> <tr> <td valign=top align=left nowrap> <font size='2'><b><?php echo $row['title']; ?></b> </font></td> </tr> </table 6></td> </tr> <tr> <td colspan='2' align=center nowrap> <br> <span class="part2" style="font-size:12pt"><b><font size=2>Original Price</font>: <font color=#000000><?php echo $row['price']; ?></font> <br> </b></span><b><br> <br> <table 7 height="54" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor='#FFFFFF'> <!--DWLayoutTable--> <tr align="center"> <td> </td> </tr> <tr> <td ><br> <center> <b><font size='2'>Call to place your order<br> <font size='3'>555-555-5555<br> </font></font></b> </center></td> </tr> </table 7> </b></td> </tr> </table 5></td> <td align=right valign=top> <br> <table 7 border="0" cellpadding="2" cellspacing="1" bgcolor="666666" width="100%"> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>CPU</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><span class="data"><?php echo $row['processor']; ?></span></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033CC"><font color="#FFFFFF"><span class="part2"><b>MEMORY</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><span class="data"><?php echo $row['memory']; ?> </span></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>HARD DRIVE</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['hdd']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>OPTICAL DRIVE</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><span class="data"><?php echo $row['cdrom']; ?> </span></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>FLOPPY</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><span class="data"><?php echo $row['floppy']; ?> </span></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>MODEM</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['modem']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>NETWORK</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['nic']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>DISPLAY</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['display']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>DISPLAY ADAPTER</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['vcard']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>SOUND</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['audio']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>KEYBOARD</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['keybd']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>POINTING DEVICE</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['mouse']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>EXPANSION SLOTS</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['expansion']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>A/C ADAPTER</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['acplug']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>BATTERY</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['battery']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>SOFTWARE</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['software']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>WARRANTY</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['warranty']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>CONDITION</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['condition']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>WEIGHT</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['weight']; ?></td> </tr> <tr> <td width="101" valign="top" nowrap bgcolor="#0033cc"><font color="#FFFFFF"><span class="part2"><b>DIMENSIONS</b></span><span class="data"> </span></font></td> <td align="left" valign="top" bgcolor="#e3e3e3"><?php echo $row['dimension']; ?></td> </tr> </table 7></td> </tr> <tr> </tr> </table> <br /> <p> </p> </div> <?php require_once("_sidebar.php"); ?> <div class="clear"></div> </div> <div class="clear"></div> </div> <?php require_once("_footer.php"); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/122067-trying-to-pull-information-from-a-mysql-db/#findComment-630349 Share on other sites More sharing options...
daniel5455 Posted August 31, 2008 Author Share Posted August 31, 2008 bump Link to comment https://forums.phpfreaks.com/topic/122067-trying-to-pull-information-from-a-mysql-db/#findComment-630543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.