how to display image from database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mirianCalin
    New Member
    • Feb 2008
    • 35

    #31
    Originally posted by harshmaul
    okies, i never read that.

    can you post some mark up this time.

    Also your table definition would help
    hi!!
    what mark up?
    my table name is "product"
    the fields inside are:

    pid (int) > product's id
    title (text) > name of the product
    imgdata (longlob) > the image
    feature (text) > the product's feature.. this is also my problem when displaying.. like what i've mention above..

    Comment

    • harshmaul
      Recognized Expert Contributor
      • Jul 2007
      • 490

      #32
      Hi again mate,

      I think i know the problem...

      replace the line that you have printing out the string with a piece of code that swaps carriage returns with <br/>'s

      something like this.....


      Code:
      <?php echo nl2br(mysql_result($rsPix,$i,"feature")); ?>
      BTW, markup is what you get when you view source in the browser after the PHP is run

      Comment

      • mirianCalin
        New Member
        • Feb 2008
        • 35

        #33
        Originally posted by harshmaul
        Hi again mate,

        I think i know the problem...

        replace the line that you have printing out the string with a piece of code that swaps carriage returns with <br/>'s

        something like this.....


        Code:
        <?php echo nl2br(mysql_result($rsPix,$i,"feature")); ?>
        BTW, markup is what you get when you view source in the browser after the PHP is run
        hello.. thanks again for the reply..

        this is the code for displaying the image's title, image & feature..
        the only problem now is that i dont have a code for displaying the image..
        the code only displays the title and feature..
        [code=php]
        <?php
        $errmsg = "";
        if (! @mysql_connect( "localhost","ro ot","")) {
        $errmsg = "Cannot connect to database";
        }
        @mysql_select_d b("upload");

        $pid = $_GET['pid'];
        $strSQL = "SELECT * FROM sharp where (pid = '$pid')";

        $rsPIX = mysql_query($st rSQL);
        $num=mysql_numr ows($rsPIX);
        $i=0;

        if ($num > 0){
        $title = mysql_result($r sPIX,$i,"title" );
        $description = nl2br(mysql_res ult($rsPIX,$i," feature"));
        }
        echo $title . "<br>";

        echo $description . "<br>";
        ?>[/code]
        Last edited by pbmods; Jan 17 '09, 12:50 AM. Reason: Added CODE tags.

        Comment

        • harshmaul
          Recognized Expert Contributor
          • Jul 2007
          • 490

          #34
          Originally posted by mirianCalin
          [code=php]
          <?php
          $errmsg = "";
          if (! @mysql_connect( "localhost","ro ot","")) {
          $errmsg = "Cannot connect to database";
          }
          @mysql_select_d b("upload");

          $pid = $_GET['pid'];
          $strSQL = "SELECT * FROM sharp where (pid = '$pid')";

          $rsPIX = mysql_query($st rSQL);
          $num=mysql_numr ows($rsPIX);
          $i=0;

          if ($num > 0){
          $title = mysql_result($r sPIX,$i,"title" );
          $description = nl2br(mysql_res ult($rsPIX,$i," feature"));
          }
          echo $title . "<br>";

          echo $description . "<br>";
          ?>[/code]

          Hi.

          You've forgotton to put the image in....

          Remember the page we made that displayed the imaged using an image tag?... we need to use that again on this page. This time we have the ID though. So it will be something like this....

          Code:
          <img src="pix.php?pixID=<?php echo mysql_result($rsPIX,$i,"PixID"); ?>"/>
          Put that in the if statement and it should work!
          Last edited by pbmods; Jan 17 '09, 12:50 AM. Reason: Added CODE tags.

          Comment

          • mirianCalin
            New Member
            • Feb 2008
            • 35

            #35
            Originally posted by harshmaul
            Hi.

            You've forgotton to put the image in....

            Remember the page we made that displayed the imaged using an image tag?... we need to use that again on this page. This time we have the ID though. So it will be something like this....

            Code:
            <img src="pix.php?pixID=<?php echo mysql_result($rsPIX,$i,"PixID"); ?>"/>
            Put that in the if statement and it should work!
            i've seen my mistake..
            yeah, i've tried putting that code..
            but i forgot to put this <? ?>
            hehe.. thanks again..

            this question is out of topic..
            are you working?
            how old are you friend?

            Comment

            • mirianCalin
              New Member
              • Feb 2008
              • 35

              #36
              hey, got a problem again..
              a 4th yr.student told me that i should not use 'longblob' for saving images because it's 'heavy' for the database and i will have a problem if i export/import the database from one computer to another..

              do you have other suggestions for me?
              i have only one week to finish this site.. *sighs*

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #37
                Originally posted by mirianCalin
                hey, got a problem again..
                a 4th yr.student told me that i should not use 'longblob' for saving images because it's 'heavy' for the database and i will have a problem if i export/import the database from one computer to another..

                do you have other suggestions for me?
                i have only one week to finish this site.. *sighs*
                Are you not able to store images on the server?

                Comment

                • harshmaul
                  Recognized Expert Contributor
                  • Jul 2007
                  • 490

                  #38
                  I agree with markusn00bs and disagree to an extent....

                  Agree buecause it is heavy for the server, and you can use image file uploads.

                  And disagree as if you images are in a DB you can ensure security alot more, like put the image view page behid a log in page

                  Comment

                  • mirianCalin
                    New Member
                    • Feb 2008
                    • 35

                    #39
                    Originally posted by markusn00b
                    Are you not able to store images on the server?
                    the images are only stored in the DB..

                    Comment

                    • mirianCalin
                      New Member
                      • Feb 2008
                      • 35

                      #40
                      Originally posted by harshmaul
                      I agree with markusn00bs and disagree to an extent....

                      Agree buecause it is heavy for the server, and you can use image file uploads.

                      And disagree as if you images are in a DB you can ensure security alot more, like put the image view page behid a log in page
                      so, do you have any suggestions?
                      i am not doing the site now 'cause i might start all over again..

                      Comment

                      • harshmaul
                        Recognized Expert Contributor
                        • Jul 2007
                        • 490

                        #41
                        how many bytes worth of space are all the photos you will be uploading.

                        my personal preference is to store images in the DB, if the server can't handle it update the hardware, and software.

                        Comment

                        • mirianCalin
                          New Member
                          • Feb 2008
                          • 35

                          #42
                          Originally posted by harshmaul
                          how many bytes worth of space are all the photos you will be uploading.

                          my personal preference is to store images in the DB, if the server can't handle it update the hardware, and software.
                          would there be a problem if i export/import it from one pc to another?

                          Comment

                          • harshmaul
                            Recognized Expert Contributor
                            • Jul 2007
                            • 490

                            #43
                            How much space worth of images are you likely to save in the DB?

                            is it a commercial project, uni project?

                            Comment

                            • mirianCalin
                              New Member
                              • Feb 2008
                              • 35

                              #44
                              Originally posted by harshmaul
                              How much space worth of images are you likely to save in the DB?

                              is it a commercial project, uni project?
                              hi.. i've already solved this.. hehe.. i'll be continuing what i am doing.. but i'll be having a tutorial for server side coding...

                              Comment

                              • harshmaul
                                Recognized Expert Contributor
                                • Jul 2007
                                • 490

                                #45
                                cool. if you're pnly returning the images one at a time, and you becareful with your "select *" 's it won't slow anything down too much

                                Comment

                                Working...