joshgarrod Posted June 29, 2007 Share Posted June 29, 2007 Hi, I am adding the url of an image to a database an then displaying the data in a table, i want the url to display as a link to the image, how do i go about making this happen? <!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>View spares stock</title> <style type="text/css"> <!-- #Layer1 { position:absolute; left:14px; top:63px; width:196px; height:22px; z-index:1; } .style1 {font-family: Arial, Helvetica, sans-serif} .style2 {font-family: Arial, Helvetica, sans-serif; color: #FFFFFF; } .style3 {color: #0000FF} #Layer2 { position:absolute; left:378px; top:63px; width:87px; height:21px; z-index:2; } .style4 {color: #0000FF; font-family: Arial, Helvetica, sans-serif; } --> </style> </head> <body> <div class="style1" id="Layer1"><a href="index.php?page=Search1" class="style3">Click here to search stock </a></div> <TABLE WIDTH="100%" HEIGHT="40" BORDER="0" CELLPADDING="10" CELLSPACING="5" BGCOLOR="#FFFFFF"> <TR bgcolor="#F0F0F0"> <TD width="8%" HEIGHT="40" ALIGN=bottom class="style1" ID="header"><strong><em><FONT SIZE="1" COLOR="#8A8A8A">ID number </FONT></em></strong></TD> <TD width="10%" ALIGN=middle class="style1" ID="header"><strong><em><FONT COLOR="#8A8A8A" SIZE="1">Stock number </FONT></em></strong></TD> <TD width="48%" ALIGN=middle class="style1" ID="header"><strong><em><FONT COLOR="#8A8A8A" SIZE="1">Stock description </FONT></em></strong></TD> <TD width="22%" ALIGN=middle class="style1" ID="header"><strong><em><FONT COLOR="#8A8A8A" SIZE="1">Image </FONT></em></strong></TD> <TD width="12%" ALIGN=middle class="style1" ID="header"><strong><em><FONT COLOR="#8A8A8A" SIZE="1">Item price inc. VAT </FONT></em></strong></TD> </TR> <TR> <TD HEIGHT="40" ALIGN=middle class="style2" ID="header"> </TD> <TD ALIGN=middle class="style2" ID="header"> </TD> <TD ALIGN=middle class="style2" ID="header"> </TD> <TD ALIGN=middle class="style2" ID="header"> </TD> <TD ALIGN=middle class="style2" ID="header"> </TD> </TR> <?php $con = mysql_connect("localhost","sgsdg","gsdgdsg"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ssdsfdg", $con); $query = "SELECT * FROM `stock`"; $result = mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $a=mysql_result($result,$i,"ID"); $b=mysql_result($result,$i,"StockNumber"); $c=mysql_result($result,$i,"StockDescription"); $e=mysql_result($result,$i,"Image"); $d=mysql_result($result,$i,"ItemPrice"); print ($i % 2) ? "<tr bgcolor=\"ffffff\">" : "<tr bgcolor=\"fff000\">"; print "<td align=center>$a</td>"; print "<td align=center>$b</td>"; print "<td align=center>$c</td>"; print "<td align=center>$e</td>"; print "<td align=center>$d</td>"; ++$i; } ?> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/ Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 Once you've pulled the URL from the database use something like this: echo '<a href="'.$urlvar.'">'.$urlvar.'</a>'; I think this is what you mean. Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285772 Share on other sites More sharing options...
joshgarrod Posted June 29, 2007 Author Share Posted June 29, 2007 ok where does that go or what does it replace please? could you possibly put it in my code for me please? Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285773 Share on other sites More sharing options...
hackerkts Posted June 29, 2007 Share Posted June 29, 2007 ok where does that go or what does it replace please? could you possibly put it in my code for me please? Try it yourself, so you will learn and not asking the same question in future. Learn how to query out result, http://www.tizag.com/mysqlTutorial/mysqlselect.php Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285778 Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 I won't write your code for you but if you see where you want to display the URL, try adding it there. Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285781 Share on other sites More sharing options...
joshgarrod Posted June 29, 2007 Author Share Posted June 29, 2007 ok, i have replaced the line : print "<td align=center>$e</td>"; with the line: print "<td align=center>$e</td>"; but it no longer appears in the table Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285789 Share on other sites More sharing options...
Yesideez Posted June 29, 2007 Share Posted June 29, 2007 I can't see what you're doing with $e or where you got it from ??? Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285791 Share on other sites More sharing options...
joshgarrod Posted June 29, 2007 Author Share Posted June 29, 2007 its the variable which stores the image data from the database Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285792 Share on other sites More sharing options...
joshgarrod Posted June 29, 2007 Author Share Posted June 29, 2007 thanks for the help, i found what i had to do, i was building the echo wrong thanks Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285807 Share on other sites More sharing options...
craygo Posted June 29, 2007 Share Posted June 29, 2007 well all you have to do is think of how a link is structured echo "<a href=\"the_link\">What is displayed</a>"; Now where would you put the code to get to your picture??? Link to comment https://forums.phpfreaks.com/topic/57722-solved-help-with-some-code/#findComment-285870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.