mindapolis Posted October 13, 2011 Share Posted October 13, 2011 if you have the urls to pictures in a database how would you display the actual pictures on a webpage? Here 's the code. <?php require_once("functions.php"); ?> <!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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <?php navBar(); echo "<form action=\"\" method=\"post\" name=\"catalog\">"; DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $i = 0; echo "<table>"; while ($row = mysql_fetch_array($result_set)) { echo"<tr><td width=\"400px\">($row['product_pic']). <br />{$row['product_id']}.<br />{$row['product_title']}.<br /> {$row['product_Description']}.<br />{$row['product_price']}</td></tr>"; } echo "</table>"; ?> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/ Share on other sites More sharing options...
MasterACE14 Posted October 13, 2011 Share Posted October 13, 2011 echo"<tr><td width=\"400px\"><img src="{$row['product_pic']}" />. Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1278826 Share on other sites More sharing options...
mindapolis Posted October 13, 2011 Author Share Posted October 13, 2011 Now, I'm getting this error with the code below. Parse error: syntax error, unexpected '(', expecting ',' or ';' in D:\Hosting\5246561\html\treats.php on line 37 <?php require_once("functions.php"); ?> <!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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <?php navBar(); echo "<form action=\"\" method=\"post\" name=\"catalog\">"; DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $i = 0; echo "<table>"; while ($row = mysql_fetch_array($result_set)) { echo"<tr><td width=\"400px\"><img src="($row['product_id'])" />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['product_price']}</td></tr>"; } echo "</table>"; ?> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1278994 Share on other sites More sharing options...
MasterACE14 Posted October 14, 2011 Share Posted October 14, 2011 you've put in parenthesis around product_id instead of curly braces. should be: echo"<tr><td width=\"400px\"><img src="{$row['product_id']}" />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['product_price']}</td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279186 Share on other sites More sharing options...
mindapolis Posted October 14, 2011 Author Share Posted October 14, 2011 didn't help, still getting the same error after copying the code. <?php require_once("functions.php"); ?> <!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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <?php navBar(); echo "<form action=\"\" method=\"post\" name=\"catalog\">"; DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $i = 0; echo "<table>"; while ($row = mysql_fetch_array($result_set)) { echo"<tr><td width=\"400px\"><img src="{$row['product_pic']}" />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['price']}</td></tr>"; ?> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279195 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2011 Share Posted October 14, 2011 The double-quotes that are inside of the string (those between the first and final double-quote) must be escaped OR you must instead use single-quotes inside the string. Use one or the other of the following - echo"<tr><td width=\"400px\"><img src=\"{$row['product_pic']}\" />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['price']}</td></tr>"; echo"<tr><td width='400px'><img src='{$row['product_pic']}' />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['price']}</td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279196 Share on other sites More sharing options...
mindapolis Posted October 14, 2011 Author Share Posted October 14, 2011 that helped some. I dont have any errors but where the pictures should be, it 's displaying bb Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279201 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2011 Share Posted October 14, 2011 What does the 'view source' of the page in your browser show? Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279202 Share on other sites More sharing options...
mindapolis Posted October 14, 2011 Author Share Posted October 14, 2011 It displays this. <!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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <div id = "navBar"><ul id="menu"><li class="menuOption"><a href="index.html">Home</a></li><li class="menuOption"><a href="aboutUs.html">Management Team </a></li><li class="menuOption"><a href="treats.html">Treats </a></li><li class="menuOption"><a href="charities.html">Supported Charities</a></li><li class="menuOption"><a href="order.html">Orders</a></li></ul></div><form action="" method="post" name="catalog"><table><tr><td width="400px"><img src=""http://auntievics.com/assets/WayahsWoofburgers.jpg"" /> bb Wayah's Woofburgers and fries.<br />Burger: Unbleached and rye flours, cheddar cheese, unsalter butter, beef broth, cornmeal, canola oil, garlic powder, seseme seeds, egg whites, beet and spinach powders..<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" /> bb Bo Chunky Peanut Butter Chunchies.<br />Whole wheat flour, wheat germ, crunchy peanut butter, distilled water, rolled oats canola oil, eggs.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/CuddlesCarrotCats.jpg" /> bb Miss Cuddles Carrot Catz.<br />Unbleached flour, carrots, oats, wheat germ, vegetable broth, eggs, garlic powder.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/BrunosBreakfastDrops.jpg" /> bb Bruno's Breakfast Drops.<br />Unbleached flour, oats, cheddar cheese, wheat germ, bacon, butter, brown sugar, eggs, baking soda, salt, vanilla..<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/StefisMintyMouthfuls.jpg" /> bb Stefi's Minty Mouthfuls.<br />Whole wheat flour, cake flour, peppermint leaves, milk, butter, egg, maple syrup. .<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/BlisssBananaBonz.jpg" /> bb Bliss's Banan aBonz.<br />whole wheat flour, non fat dry milk eggs, banana, canola oil, beef broth, brown sugar.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/BartsPeamuttButterNJelly.jpg" /> bb Bart's Peamutt Butter & Jelly.<br />Unbleached and whole wheat flours, cornmeal, nonfat dry milk, sugarless orange marmalade, eggs, peanut butter, distilled water and peanut butter chips.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/DixiesDillyFlowers.jpg" /> bb Dixie's Dilly Flowers.<br />Unbleached and whole wheat flours, cornmeal, nonfat dry milk, dill weed, eggs, distilled water, tapioca flours and sugar crystals.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/MandysDandyBars.jpg" /> bb Mandy's Dandy Bars.<br />Unbleached flour, whole wheat flour, cornmeal, nonfat dry milk, carob powder, egg, peanut butter, honey, water, peanut butter chips.<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/TrailMix.jpg" /> bb Chief Deputy Seamus' On the Trail Mix Cookies.<br />Unbleached flour, dried tropical fruit, distilled water, nonfat dry milk, canola oil, eggs, parsley, cinnamon, garlic powder..<br /> Price: $10</td></tr><tr><td width="400px"><img src="http://auntievics.com/assets/treats/TacoPizza.jpg" /> bb Pacos Taco Pizzas.<br />Unbleached and rye flours, beef broth, beet, spinach, garlic powders, mild taco seasoning, egg whites. .<br /> Price: $10</td></tr></table> </form> </body> </html> Do I need to change the data type of that column in the database? I'm pretty sure it 's set to text or should it be set to blob? Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279208 Share on other sites More sharing options...
MasterACE14 Posted October 14, 2011 Share Posted October 14, 2011 Use one or the other of the following - echo"<tr><td width=\"400px\"><img src=\"{$row['product_pic']}\" />{$row['product_title']}.<br />{$row['product_Description']}.<br />{$row['price']}</td></tr>"; use that, you've added in extra double quotes around $row['product_pic'] that you don't need. Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279210 Share on other sites More sharing options...
mindapolis Posted October 14, 2011 Author Share Posted October 14, 2011 I'm not following you. Don't I need those quotes for the image tag? Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279212 Share on other sites More sharing options...
MasterACE14 Posted October 14, 2011 Share Posted October 14, 2011 yes but only 1 set, not 2, if you look at your source you have 2 sets of double quotes: <img src=""http://auntievics.com/assets/WayahsWoofburgers.jpg"" /> copy paste that line from PFMaBiSmAd and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279225 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2011 Share Posted October 14, 2011 The double-quotes around that data from the first row of the result set implies that the extra double-quotes are actually stored in the data table with that particular piece of data and you should probably manually remove them by editing the table cell using your favorite database management tool (phpmyadmin or similar.) Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279227 Share on other sites More sharing options...
mindapolis Posted October 15, 2011 Author Share Posted October 15, 2011 That did it, thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/#findComment-1279540 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.