showing image from database | Newbie | | Join Date: Feb 2008
Posts: 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 -
<?
-
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");
-
-
-
-
while($myrow = mysql_fetch_array($result))
-
-
-
-
-
{//begin of loop
-
-
//now print the results:
-
-
echo "<b><u> Guest:</b></u> ";
-
-
echo "<br>Last Name: ";
-
-
echo $myrow['LastName'];
-
-
echo "<br>First Name: ";
-
-
echo $myrow['FirstName'];
-
-
echo "<br>Image: ";
-
-
echo $myrow['image'];
-
-
-
-
-
-
-
-
-
-
}//end of loop
-
-
-
?>
-
- posted this in the wrong area before, sorry
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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???
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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: ";
echo $myrow['LastName'];
echo "<br>First Name: ";
echo $myrow['FirstName'];
echo "<br>Image: ";
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
| | | 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: ";
echo $myrow['LastName'];
echo "<br>First Name: ";
echo $myrow['FirstName'];
echo "<br>Image: ";
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
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 5,134
| | | 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!
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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.
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | re: showing image from database
So in the ELSE branch you need this statement: - "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
| | | re: showing image from database Quote:
Originally Posted by ronverdonk So in the ELSE branch you need this statement: - "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
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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?? -
<?
-
include_once('../sql_connect.php');
-
$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");
-
-
if (mysql_num_rows($result) <> B.LastName ) {
-
-
-
-
{//begin of loop
-
-
//now print the results:
-
-
-
-
echo '<table>'; // start the table.
-
-
-
-
$_counter = -1; // We start 'outside' the Matrix. Unlike Neo.
-
$_cols = 4; // 4 columns. Of the Ionic variety.
-
while($myrow = mysql_fetch_array($result)){ //get array of table.
-
-
// Advance the counter and determine our 'position';
-
-
$_pos = ( ++$_counter % $_cols );
-
-
// Should we output a '<tr>'?
-
-
if( $_pos === 0 )
-
{
-
echo '<tr>';
-
}
-
-
-
/// This will create link on picture to search for user on inside.spherion.com ////
-
/// Still working on how to simply put 5-2 and pull image from inside.spherion.com at the myrow[image] call ////
-
-
echo "
-
<td>
-
<a href=\"http://inside.spherion.com/Search.aspx?k={$myrow['LastName']}&s=Search%20People\" target=\"_blank\">
-
<img src=\"" . $myrow['image']."\" /></a>
-
<b><br>Last Name:</b>
-
{$myrow['LastName']}
-
-
</td>"; // echoing out the image
-
-
-
// Should we output a '</tr>'?
-
if( $_pos === $_cols - 1 )
-
{
-
echo '</tr>';
-
}
-
}
-
if( $_counter % $_cols !== $_cols - 1 )
-
{
-
do
-
{
-
echo '<td style="visibility: hidden"> </td>';
-
}
-
while( ++$_counter % $_cols !== $_cols - 1 );
-
-
echo '</tr>';
-
}
-
-
echo '
-
</table>';
-
} //end of loop
-
-
-
} // End IF
-
else {
-
("SELECT LastName FROM nocsis WHERE LastName NOT IN (Select LastName FROM image) AND TimeOut IS NULL ORDER BY TimeIn DESC");
-
-
-
}
-
-
-
-
?>
-
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|