Connecting Tech Pros Worldwide Forums | Help | Site Map

showing image from database

Newbie
 
Join Date: Feb 2008
Posts: 22
#1: Feb 26 '08
the issue I am having is when a client logs into the system we want all their info to show up (from the nocsis table) then match the last name to the image table. All is working well with my select statement the only problem is the image doesn't show up. I believe what is diplayed is MIME. How do I get the actually image to display. Thanks in advance


Expand|Select|Wrap|Line Numbers
  1. <?
  2. include_once('../sql_connect.php');
  3.  
  4.  
  5.  
  6.     $result = mysql_query("SELECT A.LastName, A.FirstName, A.Server, A.TimeIn, A.TimeOut, B.image  FROM nocsis A, image B WHERE A.LastName = B.LastName AND A.TimeOut IS NULL ORDER BY A.TimeIn ASC");
  7.  
  8.  
  9.  
  10.         while($myrow = mysql_fetch_array($result))
  11.  
  12.  
  13.  
  14.  
  15.              {//begin of loop
  16.  
  17.                //now print the results:
  18.  
  19.            echo "<b><u> Guest:</b></u> ";
  20.  
  21.                echo "<br>Last Name:&nbsp; &nbsp;";
  22.  
  23.                echo $myrow['LastName'];
  24.  
  25.                echo "<br>First Name:&nbsp; &nbsp;";
  26.  
  27.                echo $myrow['FirstName'];
  28.  
  29.            echo "<br>Image:&nbsp; &nbsp;";
  30.  
  31.            echo $myrow['image'];   
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.              }//end of loop
  42.  
  43.  
  44. ?>
  45.  
- posted this in the wrong area before, sorry

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Feb 26 '08

re: showing image from database


You will have to show the content of image, like this[php]echo "<img src =\"" . $myrow['image']."\">"; [/php]Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#3: Feb 26 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

You will have to show the content of image, like this[php]echo "<img src =\"" . $myrow['image']."\">"; [/php]Ronald


thanks, when i add that line i get the 'X' like the link is gone and then the mime result again, has to be something i am missing???
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Feb 26 '08

re: showing image from database


Quote:

Originally Posted by matthewroth

thanks, when i add that line i get the 'X' like the link is gone and then the mime result again, has to be something i am missing???

Another way is[php]$image = $myrow['image'];
header("Content-type: image/jpeg");
print $image;[/php]Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#5: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

Another way is[php]$image = $myrow['image'];
header("Content-type: image/jpeg");
print $image;[/php]Ronald


your first way actually worked after i set the image as a link in mysql image field instead of the actual file. think i will leave it like that. Thanks alot.

how about another issue on this subject. how would i get a default image to show up if the person signing is not in my database
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Feb 27 '08

re: showing image from database


I'll put it inside the total code in the ELSE branch:[php]
<?php
include_once('../sql_connect.php');
$result = mysql_query("SELECT A.LastName, A.FirstName, A.Server, A.TimeIn, A.TimeOut, B.image FROM nocsis A, image B WHERE A.LastName = B.LastName AND A.TimeOut IS NULL ORDER BY A.TimeIn ASC");
if (mysql_num_rows($result) > 0) {
while($myrow = mysql_fetch_array($result)) {//begin of loop
//now print the results:
echo "<b><u> Guest:</b></u> ";
echo "<br>Last Name:&nbsp; &nbsp;";
echo $myrow['LastName'];
echo "<br>First Name:&nbsp; &nbsp;";
echo $myrow['FirstName'];
echo "<br>Image:&nbsp; &nbsp;";
echo "<img src =\"" . $myrow['image']."\">";
} //end of loop
} // End IF
else {
echo "<img src ='default.jpg'>";
}
?>
[/php]Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#7: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

I'll put it inside the total code in the ELSE branch:[php]
<?php
include_once('../sql_connect.php');
$result = mysql_query("SELECT A.LastName, A.FirstName, A.Server, A.TimeIn, A.TimeOut, B.image FROM nocsis A, image B WHERE A.LastName = B.LastName AND A.TimeOut IS NULL ORDER BY A.TimeIn ASC");
if (mysql_num_rows($result) > 0) {
while($myrow = mysql_fetch_array($result)) {//begin of loop
//now print the results:
echo "<b><u> Guest:</b></u> ";
echo "<br>Last Name:&nbsp; &nbsp;";
echo $myrow['LastName'];
echo "<br>First Name:&nbsp; &nbsp;";
echo $myrow['FirstName'];
echo "<br>Image:&nbsp; &nbsp;";
echo "<img src =\"" . $myrow['image']."\">";
} //end of loop
} // End IF
else {
echo "<img src ='default.jpg'>";
}
?>
[/php]Ronald


You have been a great help. appreciate it

hmmm kinda works just no image (i did add a default image) is displayed when the LastName does not match in the table.

also if you're in the mood how would i get the images to show up next to each other rather than in a column
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 5,134
#8: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by matthewroth


also if you're in the mood how would i get the images to show up next to each other rather than in a column

You might want to check this thread for a neat little work around!
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#9: Feb 27 '08

re: showing image from database


Yes, that is a neat piece of code. I couldn't do it better! Justr replace the url's with the images and their text.

Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#10: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by matthewroth

You have been a great help. appreciate it

hmmm kinda works just no image (i did add a default image) is displayed when the LastName does not match in the table.

also if you're in the mood how would i get the images to show up next to each other rather than in a column


in the if statement would there be a way to state that if lastname not in table nocsis to display a default image
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#11: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by matthewroth

in the if statement would there be a way to state that if lastname not in table nocsis to display a default image

But that is already in the code, you just have to replace the image name with the path/name of the one you want to display.[php] else {
echo "<img src ='your_image_name'>";[/php]Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#12: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

But that is already in the code, you just have to replace the image name with the path/name of the one you want to display.[php] else {
echo "<img src ='your_image_name'>";[/php]Ronald


the problem with that is it is searching for a 0 result. when someone signs in whether they have an image or not they still get logged in thus the result not being 0. only time the image appears is when no one is signed in.
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#13: Feb 27 '08

re: showing image from database


So in the ELSE branch you need this statement:
Expand|Select|Wrap|Line Numbers
  1. "SELECT A.LastName, A.FirstName, A.Server, A.TimeIn, A.TimeOut, FROM nocsis A WHERE A.TimeOut IS NULL ORDER BY A.TimeIn ASC");
Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#14: Feb 27 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

So in the ELSE branch you need this statement:

Expand|Select|Wrap|Line Numbers
  1. "SELECT A.LastName, A.FirstName, A.Server, A.TimeIn, A.TimeOut, FROM nocsis A WHERE A.TimeOut IS NULL ORDER BY A.TimeIn ASC");
Ronald

wouldnt the select statement need to compare the 2 tables somehow and select the LastName in one and not the other
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#15: Feb 27 '08

re: showing image from database


I don't know from which of the two tables you select or what table indicates that he has an image I just wanted to point out that you had to do a new select in case the result of the first select was 0.

Ronald
Newbie
 
Join Date: Feb 2008
Posts: 22
#16: Feb 28 '08

re: showing image from database


Quote:

Originally Posted by ronverdonk

I don't know from which of the two tables you select or what table indicates that he has an image I just wanted to point out that you had to do a new select in case the result of the first select was 0. .

Ronald

Think I am on the right track. my query works with mysql when i do the else select i get the user that does not have a picture, i just cant seem to figure out how to display it or could it be that my if statement is jacked up. this code is got me going in circles. i didnt think it would be that hard to say if user signs in this table1 and has photo in this table2 display picture from table2 else if user signs in table1 and has no image in table2 show default image. any ideas??

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include_once('../sql_connect.php');
  3.     $result = mysql_query("SELECT A.LastName, A.TimeOut, B.image, B.LastName  FROM nocsis A, image B WHERE A.LastName = B.LastName AND A.TimeOut IS NULL ORDER BY A.TimeIn DESC");
  4.  
  5.   if (mysql_num_rows($result) <> B.LastName ) {           
  6.  
  7.  
  8.  
  9. {//begin of loop
  10.  
  11.                //now print the results:
  12.  
  13.  
  14.  
  15.            echo '<table>'; // start the table.
  16.  
  17.  
  18.  
  19. $_counter = -1;  // We start 'outside' the Matrix.  Unlike Neo.
  20. $_cols = 4; // 4 columns.  Of the Ionic variety.
  21. while($myrow = mysql_fetch_array($result)){ //get array of table.
  22.  
  23.     // Advance the counter and determine our 'position';
  24.  
  25. $_pos = ( ++$_counter % $_cols );
  26.  
  27.     // Should we output a '<tr>'?
  28.  
  29. if( $_pos === 0 )
  30.     {
  31.         echo '<tr>';
  32.     }
  33.  
  34.  
  35. /// This will create link on picture to search for user on inside.spherion.com ////
  36. /// Still working on how to simply put 5-2 and pull image from inside.spherion.com at the myrow[image] call ////
  37.  
  38. echo "
  39. <td>
  40. <a href=\"http://inside.spherion.com/Search.aspx?k={$myrow['LastName']}&s=Search%20People\" target=\"_blank\">
  41. <img src=\"" . $myrow['image']."\" /></a>
  42. <b><br>Last Name:</b>
  43. {$myrow['LastName']}
  44.  
  45.  </td>"; // echoing out the image   
  46.  
  47.  
  48. // Should we output a '</tr>'?
  49.     if( $_pos === $_cols - 1 )
  50.     {
  51.         echo '</tr>';
  52.     }
  53. }
  54. if( $_counter % $_cols !== $_cols - 1 )
  55. {
  56.     do
  57.     {
  58.         echo '<td style="visibility: hidden">&nbsp;</td>';
  59.     }
  60.     while( ++$_counter % $_cols !== $_cols - 1 );
  61.  
  62.     echo '</tr>';
  63. }
  64.  
  65. echo '
  66. </table>';
  67. } //end of loop
  68.  
  69.  
  70. } // End IF
  71.  else {
  72. ("SELECT LastName FROM nocsis WHERE LastName NOT IN (Select LastName FROM image) AND TimeOut IS NULL ORDER BY TimeIn DESC");
  73.  
  74.  
  75.  }
  76.  
  77.  
  78.  
  79. ?>
  80.  
Reply