showing image from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matthewroth
    New Member
    • Feb 2008
    • 22

    showing image from database

    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


    Code:
    <?
    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:&nbsp; &nbsp;";
     
                   echo $myrow['LastName'];
     
                   echo "<br>First Name:&nbsp; &nbsp;";
     
                   echo $myrow['FirstName'];
     
               echo "<br>Image:&nbsp; &nbsp;";
     
               echo $myrow['image'];   
     
     
                   
     
     
     
     
     
     
                 }//end of loop
     
     
    ?>
    - posted this in the wrong area before, sorry
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

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

    Comment

    • matthewroth
      New Member
      • Feb 2008
      • 22

      #3
      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???

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        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

        Comment

        • matthewroth
          New Member
          • Feb 2008
          • 22

          #5
          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

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            I'll put it inside the total code in the ELSE branch:[php]
            <?php
            include_once('. ./sql_connect.php ');
            $result = mysql_query("SE LECT 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_arr ay($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:&nbs p; &nbsp;";
            echo "<img src =\"" . $myrow['image']."\">";
            } //end of loop
            } // End IF
            else {
            echo "<img src ='default.jpg'> ";
            }
            ?>
            [/php]Ronald

            Comment

            • matthewroth
              New Member
              • Feb 2008
              • 22

              #7
              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("SE LECT 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_arr ay($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:&nbs p; &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

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                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!

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  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

                  Comment

                  • matthewroth
                    New Member
                    • Feb 2008
                    • 22

                    #10
                    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

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      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_na me'>";[/php]Ronald

                      Comment

                      • matthewroth
                        New Member
                        • Feb 2008
                        • 22

                        #12
                        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_na me'>";[/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.

                        Comment

                        • ronverdonk
                          Recognized Expert Specialist
                          • Jul 2006
                          • 4259

                          #13
                          So in the ELSE branch you need this statement:
                          Code:
                          "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

                          Comment

                          • matthewroth
                            New Member
                            • Feb 2008
                            • 22

                            #14
                            Originally posted by ronverdonk
                            So in the ELSE branch you need this statement:
                            Code:
                            "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

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              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

                              Comment

                              Working...