By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

showing image from database

P: 22
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
Feb 26 '08 #1
Share this Question
Share on Google+
15 Replies


ronverdonk
Expert 2.5K+
P: 4,258
You will have to show the content of image, like this[php]echo "<img src =\"" . $myrow['image']."\">"; [/php]Ronald
Feb 26 '08 #2

P: 22
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???
Feb 26 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 26 '08 #4

P: 22
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
Feb 27 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #6

P: 22
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
Feb 27 '08 #7

Markus
Expert 5K+
P: 6,050

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!
Feb 27 '08 #8

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #9

P: 22
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
Feb 27 '08 #10

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #11

P: 22
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.
Feb 27 '08 #12

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #13

P: 22
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
Feb 27 '08 #14

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #15

P: 22
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.  
Feb 28 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.