Jump to content

Problems displaying a picture from a db


jackie11

Recommended Posts

Hi

I am having a problem with one of my other pages, I am trying to display a picture from my db, based on the results of a search, but I can seem to fix the coding so that it works, any suggestions, I have managed to to get it to display everything but the picture just will not work

The code is:

[code]
<html>
<head><title>Employee Index</title></head>
<body>

<h1><img src="etc/Logo_pic_2.JPG"></h1>

<?php

$search = "%" . $_POST["search"] . "%";
 
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("employee_index") or die(mysql_error());


  $query = "SELECT * FROM employee WHERE Surname LIKE '$search'";
  $result = mysql_query ($query)or die(mysql_error());
   

if (!mysql_num_rows($result)) {
print "<p><BR><B>Sorry no results found - please try again!</BR> </p>" ;


exit;
}
else
{

    while ($row = mysql_fetch_array ($result,MYSQL_ASSOC)) {
 
$Employee_ID = $row['Employee_ID'];
$Surname = $row['Surname'];
$Forename = $row['Forename'];
$Job_title = $row['Job_title'];
$Office_location = $row['Office_location'];
$Telephone = $row['Telephone'];
$Email = $row['Email'];
$Expertise = $row['Expertise'];
$Hobbies = $row['Hobbies'];
$DOB = $row['DOB'];
$Picture = <a href='../test_2/pics/{$row['Picture']}' border='0'>
            <img src='../test_2/pics/{$row['Picture']}' border='0'
            width='90' height='100'></a>;
}
}

echo "<table cellspacing='15'>";
  echo "<tr><td colspan='20'><hr></td></tr>";
  echo "<th>ID</th><th>Picture</th><th></TD><th>Surname</th><th>Forename</th><th>Job Title</th>
  <th>Office Location</th><th>Telephone</th>
  <th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>";
  echo "<tr><td colspan='20'><hr></td></tr>";


      echo "
          <td>$Employee_ID</td>\n
          <td><td>$Picture</td>\n
          <td>$Surname</td>\n
            <td>$Forename</td>\n
            <td>$Job_title</td>\n
              <td>$Office_location</td>\n
              <td>$Telephone</td>\n
                <td>$Email</td>\n
                <td>$Expertise</td>\n
                  <td>$Hobbies</td>\n
                  <td>$DOB</td>\n
                   
          </tr>\n";
    echo "<tr><td colspan='20'><hr></td></tr>\n";

  echo "</table>\n";
 
?>

<p style="text-align: left;">
<a href="index.html">
<img style="border: 0px solid ; width: 94px; height: 47px;" alt="Home" src="etc/Home_button.JPG"></a></p>

</span></span>


</body>
</html>


[/code]

Thanks

Jackie ;)
Link to comment
https://forums.phpfreaks.com/topic/34941-problems-displaying-a-picture-from-a-db/
Share on other sites

Just enclose your variables when they have mixed variable and constant strings together.


[code]$Picture = "<a href='../test_2/pics/" . $row['Picture'] . "' border='0'><img src='../test_2/pics/" . $row['Picture'] . "' border='0' width='90' height='100'></a>"[/code]

The curly brackets, {$row['Picture']} were fine, I just used the dot or concentration operator so you could see how I combine the string and embedded variables together! The variable $Picture is no enclosed with [b]"[/b]variable_value[b]"[/b]


printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.