Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/249009-pictures-from-a-database/
Share on other sites

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>

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>";

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>

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>";

 

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? 

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.

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.)

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.