how to display image from database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harshmaul
    Recognized Expert Contributor
    • Jul 2007
    • 490

    #16
    Hi again mate,

    First we'll sort out the table then we'll stick in the title....

    i think i spoted the error with my code....


    try this...


    Code:
    <?php
    $errmsg = "";
    if (! @mysql_connect("localhost","root",""))
        {
            $errmsg = "Cannot connect to database";
        }
     
    @mysql_select_db("upload");
     
    $strSQL = "select * from pix";
    $rsPix = mysql_query($strSQL);
    $numRows = mysql_numrows($rsPix);
    $i = 0;
    ?>
    <table>
        <tr>
            <?php
            while($i < $numRows){
            ?>
                <td>
                <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
                </td>
            <?php
            $i++;
                if ($i%3 == 0){
            ?>
        </tr><tr>
                <?php
                }
            ?>
            <?php
    
            }
            ?>
            <?php
            if ($numRows%3 > 0){
            ?>
                <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
            <?php
            }
            ?>
        </tr>
    </table>
    i've moved the increment before the if statement.

    Comment

    • mirianCalin
      New Member
      • Feb 2008
      • 35

      #17
      Originally posted by harshmaul
      Hi again mate,

      First we'll sort out the table then we'll stick in the title....

      i think i spoted the error with my code....


      try this...


      Code:
      <?php
      $errmsg = "";
      if (! @mysql_connect("localhost","root",""))
          {
              $errmsg = "Cannot connect to database";
          }
       
      @mysql_select_db("upload");
       
      $strSQL = "select * from pix";
      $rsPix = mysql_query($strSQL);
      $numRows = mysql_numrows($rsPix);
      $i = 0;
      ?>
      <table>
          <tr>
              <?php
              while($i < $numRows){
              ?>
                  <td>
                  <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
                  </td>
              <?php
              $i++;
                  if ($i%3 == 0){
              ?>
          </tr><tr>
                  <?php
                  }
              ?>
              <?php
      
              }
              ?>
              <?php
              if ($numRows%3 > 0){
              ?>
                  <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
              <?php
              }
              ?>
          </tr>
      </table>
      i've moved the increment before the if statement.
      hello again..
      i've tried the code, and it works!!
      yehey!!.. thanks again!!

      so, where will i have to put the code for the title of the image?
      i want it to be under the image

      ex:

      # # #
      image1 image2 image3

      thanks again for the reply!!
      thanks..

      Comment

      • harshmaul
        Recognized Expert Contributor
        • Jul 2007
        • 490

        #18
        Hi again,
        I'm getting excited its almost done!!!

        can you not line break and place it under the photo? like this...


        Code:
                    <td>
                    <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
        <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
                    </td>
        If this will do excellent, and if not i do have another solution but thats gonna take a while to code out.

        Comment

        • mirianCalin
          New Member
          • Feb 2008
          • 35

          #19
          Originally posted by harshmaul
          Hi again,
          I'm getting excited its almost done!!!

          can you not line break and place it under the photo? like this...


          Code:
                      <td>
                      <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
          <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
                      </td>
          If this will do excellent, and if not i do have another solution but thats gonna take a while to code out.
          hello again, hey thanks for the help..
          really, really thanks..
          but im still far from being done.. hehe..
          i still have to make the images serve as a link to their features..
          thank you very BIG!!

          Comment

          • harshmaul
            Recognized Expert Contributor
            • Jul 2007
            • 490

            #20
            No problems mate, i like helping! (keeps me sane)

            Comment

            • mirianCalin
              New Member
              • Feb 2008
              • 35

              #21
              Originally posted by harshmaul
              No problems mate, i like helping! (keeps me sane)
              hi.. im here again.. been busy with our thesis.. hehe..
              i have a question again.. you have already told me how to display the images and its' corresponding titles..
              i am now trying to make the image's title to be a link for the image's features.. but i really cant do it..

              ex:

              # # #
              pic1 pic2 pic3

              pic1.php will be responsible for displaying the features of pic1
              pic2.php will be responsible for displaying the features of pic2 and so on..
              i have tried adding codes to the codes you've given me but i know its not correct.. hehe.. im stuck.. here's the code:
              [code=php]
              <td>
              <center><img src="pix.php?pi d=<?php echo mysql_result($r sPix,$i,"pid"); ?>"/></center><br/>
              <center><a href = "<?php echo mysql_result($r sPix,$i,"title" ) . \".php\"; ?>"><?php echo mysql_result($r sPix,$i,"title" ); ?></a></center>
              </td>[/code]
              Last edited by pbmods; Jan 17 '09, 12:46 AM. Reason: Added CODE tags.

              Comment

              • harshmaul
                Recognized Expert Contributor
                • Jul 2007
                • 490

                #22
                Hi again mate,

                Code:
                <td>
                <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
                <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
                </td>
                That will print the links as per your specification. BUT, don't you think it would be better to have one dynamic page that changes content depending on and ID that you can append to the querystring?

                Are you storing the details of the images on the DB? or is the pages hardcoded with content?

                Comment

                • mirianCalin
                  New Member
                  • Feb 2008
                  • 35

                  #23
                  Originally posted by harshmaul
                  Hi again mate,

                  Code:
                  <td>
                  <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
                  <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
                  </td>
                  That will print the links as per your specification. BUT, don't you think it would be better to have one dynamic page that changes content depending on and ID that you can append to the querystring?

                  Are you storing the details of the images on the DB? or is the pages hardcoded with content?
                  the code that you've given is working..
                  thanks again..
                  but can you tell me more about that one dynamic page.. guess that's easier..

                  Comment

                  • mirianCalin
                    New Member
                    • Feb 2008
                    • 35

                    #24
                    Originally posted by harshmaul
                    Hi again mate,

                    Code:
                    <td>
                    <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
                    <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
                    </td>
                    That will print the links as per your specification. BUT, don't you think it would be better to have one dynamic page that changes content depending on and ID that you can append to the querystring?

                    Are you storing the details of the images on the DB? or is the pages hardcoded with content?
                    i think i understand what you're telling me.. but, am i going to use href for that dynamic page? if yes, what will handle the "id" of the image?,, or maybe i just really dont get the coding process.. but i understand the logic of having a dynamic page (less coding instead of using my idea) hehe.. help again..

                    Comment

                    • harshmaul
                      Recognized Expert Contributor
                      • Jul 2007
                      • 490

                      #25
                      Hi again,

                      For this you will need two pages.....


                      One the first page print out this href in the loop i gave you previously...

                      Code:
                      <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
                      Then on the other "dynaimc page" do something like this....

                      Code:
                      <?php
                      $pixID = $_GET['pixID'];
                      //A bit of DB logic here to get the record from the DB using $pixID
                      $strSQL = "SELECT * FROM tblPix";
                      $strSQL .= " WHERE pixID = $pixID";
                      $rsPIX = mysql_query($strSQL);
                      $num=mysql_numrows($rsPIX);
                      $i=0;
                      
                      if ($num < 0){
                      $title = mysql_result($rsPIX,$i,"pixTitle");
                      $description = mysql_result($rsPIX,$i,"pixDescription");
                      }
                      //Now you can print out the two variables there in the page containing the Title and Description.
                      //I need to make my normal point as this code will need some fixing as i again haven't tested, its ust to point you in the write direction!
                      ?>

                      I hope that makes sense

                      Comment

                      • mirianCalin
                        New Member
                        • Feb 2008
                        • 35

                        #26
                        Originally posted by harshmaul
                        Hi again,

                        For this you will need two pages.....


                        One the first page print out this href in the loop i gave you previously...

                        Code:
                        <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
                        Then on the other "dynaimc page" do something like this....

                        Code:
                        <?php
                        $pixID = $_GET['pixID'];
                        //A bit of DB logic here to get the record from the DB using $pixID
                        $strSQL = "SELECT * FROM tblPix";
                        $strSQL .= " WHERE pixID = $pixID";
                        $rsPIX = mysql_query($strSQL);
                        $num=mysql_numrows($rsPIX);
                        $i=0;
                        
                        if ($num < 0){
                        $title = mysql_result($rsPIX,$i,"pixTitle");
                        $description = mysql_result($rsPIX,$i,"pixDescription");
                        }
                        //Now you can print out the two variables there in the page containing the Title and Description.
                        //I need to make my normal point as this code will need some fixing as i again haven't tested, its ust to point you in the write direction!
                        ?>

                        I hope that makes sense
                        i have put the 1st code on my "productDisplay .php",
                        how about the 2nd one? is it another file? if yes, what file name should i name it?

                        Comment

                        • mirianCalin
                          New Member
                          • Feb 2008
                          • 35

                          #27
                          Originally posted by mirianCalin
                          i have put the 1st code on my "productDisplay .php",
                          how about the 2nd one? is it another file? if yes, what file name should i name it?
                          hi, im sorry.. i have already done it (i get stupid sometimes.. hehe).. just edited some of your codes..
                          question again..
                          why is it that when i display the "feature" of the image, it is not displayed properly.. i mean, it looks like this in my database:

                          * World's Highest Resolution Full HD Panel (1920 x 1080 pixels)
                          * New Sophisticated Piano Black Finish Design
                          * Four-Wavelength Backlight System to deliver natural, pure red
                          * Viewing angles: 1760 H/V

                          but it looks like this when it was shown..

                          * World's Highest Resolution Full HD Panel (1920 x 1080 pixels) * New Sophisticated Piano Black Finish Design * Four-Wavelength Backlight System to deliver natural, pure red * Viewing angles: 1760 H/V

                          i also need to display the image again that i choose to view the feature..
                          something like:

                          *title*
                          *image*
                          *feature*

                          i can display the title & the feature.. the image is my problem..

                          thanks again for the reply..

                          Comment

                          • harshmaul
                            Recognized Expert Contributor
                            • Jul 2007
                            • 490

                            #28
                            Oops, i didn't proof read my code....

                            Letme try that one again!


                            on the page that lists the images (name doen't matter) put this....

                            <a href="imageDeta ils.php?pixID=< ?php echo mysql_result($r sPix,$i,"pixID" ); ?>"/>View details for <?php echo mysql_result($r sPix,$i,"pixTit le"); ?></a>

                            Then on the other "dynaimc page" (in my instance called imageDetails.ph p) do something like this....

                            [code=php]<?php
                            $pixID = $_GET['pixID'];
                            //A bit of DB logic here to get the record from the DB using $pixID
                            $strSQL = "SELECT * FROM tblPix";
                            $strSQL .= " WHERE pixID = $pixID";
                            $rsPIX = mysql_query($st rSQL);
                            $num=mysql_numr ows($rsPIX);
                            $i=0;

                            if ($num < 0){
                            $title = mysql_result($r sPIX,$i,"pixTit le");
                            $description = mysql_result($r sPIX,$i,"pixDes cription");
                            }
                            //Now you can print out the two variables there in the page containing the Title and Description.
                            //I need to make my normal point as this code will need some fixing as i again haven't tested, its ust to point you in the write direction!
                            ?>[/code]
                            Last edited by pbmods; Jan 17 '09, 12:47 AM. Reason: Fixed CODE tags.

                            Comment

                            • mirianCalin
                              New Member
                              • Feb 2008
                              • 35

                              #29
                              Originally posted by harshmaul
                              Oops, i didn't proof read my code....

                              Letme try that one again!


                              on the page that lists the images (name doen't matter) put this....

                              <a href="imageDeta ils.php?pixID=< ?php echo mysql_result($r sPix,$i,"pixID" ); ?>"/>View details for <?php echo mysql_result($r sPix,$i,"pixTit le"); ?></a>


                              Then on the other "dynaimc page" (in my instance called imageDetails.ph p) do something like this....


                              Code: ( text )
                              <?php
                              $pixID = $_GET['pixID'];
                              //A bit of DB logic here to get the record from the DB using $pixID
                              $strSQL = "SELECT * FROM tblPix";
                              $strSQL .= " WHERE pixID = $pixID";
                              $rsPIX = mysql_query($st rSQL);
                              $num=mysql_numr ows($rsPIX);
                              $i=0;

                              if ($num < 0){
                              $title = mysql_result($r sPIX,$i,"pixTit le");
                              $description = mysql_result($r sPIX,$i,"pixDes cription");
                              }
                              //Now you can print out the two variables there in the page containing the Title and Description.
                              //I need to make my normal point as this code will need some fixing as i again haven't tested, its ust to point you in the write direction!
                              ?>
                              hi.. sorry for the late reply..
                              i had already solved this, and i had same changes with what you did.. (",)
                              have you read my post above your reply?
                              that's my latest problem..
                              hehe..
                              thanks again..

                              Comment

                              • harshmaul
                                Recognized Expert Contributor
                                • Jul 2007
                                • 490

                                #30
                                okies, i never read that.

                                can you post some mark up this time.

                                Also your table definition would help

                                Comment

                                Working...