473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to display image from database?

i am doing a site for appliance center..
i need to display all the products that the company offers, but my problem is that i cant display ALL the images in my database.. the first entry on the database is the only one that displays..
i am using mysql as database

here's the code.. tell me what's my error and pls. kindly edit it..

**imgdata = it is where i store the image.. longblob is the data type
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     $errmsg = "";
  3.     if (! @mysql_connect("localhost","root",""))
  4.         {
  5.                 $errmsg = "Cannot connect to database";
  6.                             }
  7.     @mysql_select_db("upload");
  8.  
  9.     $gotten = @mysql_query("select imgdata from pix");
  10.     header("Content-type: image/jpeg");
  11.     while ($row = mysql_fetch_array($gotten))
  12.     {
  13.         print $row['imgdata'];
  14.  
  15.     }
  16. mysql_free_result($gotten);
  17. ?>
Feb 6 '08 #1
48 41339
hi
change in the mysql_fetch_array()
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     $errmsg = "";
  3.     if (! @mysql_connect("localhost","root",""))
  4.         {
  5.                 $errmsg = "Cannot connect to database";
  6.                             }
  7.     @mysql_select_db("upload");
  8.  
  9.     $gotten = @mysql_query("select imgdata from pix");
  10.     header("Content-type: image/jpeg");
  11.  
  12. while ($row = mysql_fetch_array($gotten,MYSQL_ASSOC))
Feb 6 '08 #2
harshmaul
490 Expert 256MB
Hi,
the problem here is that you are only able to use the content disposition to send out one file.
As each blob stores a different image you will need another page thats loops through the DB, and displays the content disposition page.

Steps to achieve this....
Firstly change your select query to be based on the ID in the table, and get that ID from the query string ($_GET['ID']) or something like that.

Secondly make another page and in that page loop through the results from the table printing out an image with the content disposition page and an ID in the query string.

I can go in to more detail if you like. let me know
Feb 6 '08 #3
Hi,
the problem here is that you are only able to use the content disposition to send out one file.
As each blob stores a different image you will need another page thats loops through the DB, and displays the content disposition page.

Steps to achieve this....
Firstly change your select query to be based on the ID in the table, and get that ID from the query string ($_GET['ID']) or something like that.

Secondly make another page and in that page loop through the results from the table printing out an image with the content disposition page and an ID in the query string.

I can go in to more detail if you like. let me know
yes, please help me..
and can you show me the code?
im really new with php and im having a hard time..
thanks for the reply..
very much appreciated
Feb 7 '08 #4
hi
change in the mysql_fetch_array()
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     $errmsg = "";
  3.     if (! @mysql_connect("localhost","root",""))
  4.         {
  5.                 $errmsg = "Cannot connect to database";
  6.                             }
  7.     @mysql_select_db("upload");
  8.  
  9.     $gotten = @mysql_query("select imgdata from pix");
  10.     header("Content-type: image/jpeg");
  11.  
  12. while ($row = mysql_fetch_array($gotten,MYSQL_ASSOC))
hi!! thanks for the reply..
very much appreciated..
i'll try this tomorrow and will inform you about the result..
thanks again!!
Feb 7 '08 #5
harshmaul
490 Expert 256MB
So you need two pages.

The first page uses content disposition to output an image given an ID in the quesry string just like you have already only modify the query to select an image based on the query string. Like this.....


Call this page pix.php...

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. if (IsSet($_GET['pixID'])){
  10. $gotten = @mysql_query("select imgdata from pix where pixID = ".$_GET['pixID']);
  11. header("Content-type: image/jpeg");
  12. while ($row = mysql_fetch_array($gotten))
  13. {
  14. print $row['imgdata'];
  15.  
  16. }
  17. mysql_free_result($gotten);
  18. }
  19. ?>

the other page will have a list of img tags with the source pointing to a variation of pix.php and a query string value.


call this page list.php


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13.  
  14. while($i < $numRows){
  15. ?>
  16. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  17. <?php
  18. $i++;
  19. }
  20. ?>
Now put these into the same folder and it should work. i haven't tested you may need to debug slightly
Feb 7 '08 #6
So you need two pages.

The first page uses content disposition to output an image given an ID in the quesry string just like you have already only modify the query to select an image based on the query string. Like this.....


Call this page pix.php...

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. if (IsSet($_GET['pixID'])){
  10. $gotten = @mysql_query("select imgdata from pix where pixID = ".$_GET['pixID']);
  11. header("Content-type: image/jpeg");
  12. while ($row = mysql_fetch_array($gotten))
  13. {
  14. print $row['imgdata'];
  15.  
  16. }
  17. mysql_free_result($gotten);
  18. }
  19. ?>

the other page will have a list of img tags with the source pointing to a variation of pix.php and a query string value.


call this page list.php


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13.  
  14. while($i < $numRows){
  15. ?>
  16. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  17. <?php
  18. $i++;
  19. }
  20. ?>
Now put these into the same folder and it should work. i haven't tested you may need to debug slightly
hey, thank you very much!! it works!!
i hope i can ask you again for further problems.. :-)
thank you..
thank you..
thank you!!
Feb 8 '08 #7
harshmaul
490 Expert 256MB
hi,
absolutly no problem. i love to help. But make sure you ask in the forums so every one can learn.
Feb 8 '08 #8
hi,
absolutly no problem. i love to help. But make sure you ask in the forums so every one can learn.
i have another problem..
i also want to display the corresponding title of the image..
"title" is the field that handles the title of the image in my table
Feb 9 '08 #9
harshmaul
490 Expert 256MB
i have another problem..
i also want to display the corresponding title of the image..
"title" is the field that handles the title of the image in my table
Hi again...

Something like this..... for the page which displays all the images

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13.  
  14. while($i < $numRows){
  15. ?>
  16. <h1><?php echo mysql_result($rsPix,$i,"pixTitle"); ?></h1>
  17. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  18. <?php
  19. $i++;
  20. }
  21. ?>
Feb 9 '08 #10
Hi again...

Something like this..... for the page which displays all the images

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13.  
  14. while($i < $numRows){
  15. ?>
  16. <h1><?php echo mysql_result($rsPix,$i,"pixTitle"); ?></h1>
  17. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  18. <?php
  19. $i++;
  20. }
  21. ?>
hello!! thanks for replying again..
you're great.. it worked!!
mmm.. can i ask you again?
how can i display all the images in a table of 3 columns while the rows will depend on how many images is in my database

ex:
total # of images: 25
so, there will be 3 columns and 9 rows (the last row has only 1 image)

thanks again for the reply!!
Feb 10 '08 #11
harshmaul
490 Expert 256MB
Hi,
I appreciate your gratitude.

I don't get that last question fully.
What is the table structure for this new table (you can give me the create query if you like). I can try work it out or give you a proper solution, but i need more info this time...

:)
Feb 10 '08 #12
Hi,
I appreciate your gratitude.

I don't get that last question fully.
What is the table structure for this new table (you can give me the create query if you like). I can try work it out or give you a proper solution, but i need more info this time...

:)
ah ok, i'll explain it again..
previously, you've given me the code for displaying all the images in my database.. when i tried it, it looks like this ( # for example is the image)
# # # # # # # #

i tried putting the code inside a table.
here's the code:
Expand|Select|Wrap|Line Numbers
  1. <table>
  2. <tbody>
  3. <?
  4. if($colCtr % $cols == 0)
  5. {
  6. ?> 
  7. <tr>
  8.     <td><img src="pix.php?pid=<?php echo mysql_result($rsPix,$i,"pid"); ?>"/></td>
  9. </tr>
  10.     <? $colCtr++; 
  11. }
  12. ?>
  13. </tbody>
  14. </table>
  15.  
  16. but the output looks like this:
  17. #
  18. #
  19. #
  20. #
  21. #
  22. #
  23. #
  24. #
  25.  
what i want is to be displayed it in 3 columns while the rows will depend on the number of images in my database
ex: total number of images is 7
Expand|Select|Wrap|Line Numbers
  1. display: 
  2.           # # #
  3.           # # #
  4.           #
  5.  
ex: total number of images is 11
Expand|Select|Wrap|Line Numbers
  1. display:
  2.           # # #
  3.           # # #
  4.           # # #
  5.           # #
  6.  
ex: total number of images is 6
Expand|Select|Wrap|Line Numbers
  1. display:
  2.           # # #
  3.           # # #
  4.  
please help me again..
and thanks for the reply..
thank you very much..
Feb 11 '08 #13
harshmaul
490 Expert 256MB
Hi, again!

Try using the div solution...
(the output code will be alot cleaner).
If you definately need tables i have another solution. but i'm not proud of that code... (very messy)

Div solution....
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13. ?>
  14. <div>
  15. <?php
  16. while($i < $numRows){
  17. ?>
  18. <div style="width:33%: float:left">
  19. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  20. </div>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25. </div>

Table solution.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.             if ($i%3 == 0){
  25.         ?>
  26.     </tr><tr>
  27.             <?php
  28.             }
  29.         ?>
  30.         <?php
  31.         $i++;
  32.         }
  33.         ?>
  34.         <?php
  35.         if ($numRows%3 > 0){
  36.         ?>
  37.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  38.         <?php
  39.         }
  40.         ?>
  41.     </tr>
  42. </table>
Again i must say the code may need a spot of debugging.
Feb 11 '08 #14
Hi, again!

Try using the div solution...
(the output code will be alot cleaner).
If you definately need tables i have another solution. but i'm not proud of that code... (very messy)

Div solution....
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4. {
  5. $errmsg = "Cannot connect to database";
  6. }
  7. @mysql_select_db("upload");
  8.  
  9. $strSQL = "select * from pix";
  10. $rsPix = mysql_query($strSQL);
  11. $numRows = mysql_numrows($rsPix);
  12. $i = 0;
  13. ?>
  14. <div>
  15. <?php
  16. while($i < $numRows){
  17. ?>
  18. <div style="width:33%: float:left">
  19. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  20. </div>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25. </div>

Table solution.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.             if ($i%3 == 0){
  25.         ?>
  26.     </tr><tr>
  27.             <?php
  28.             }
  29.         ?>
  30.         <?php
  31.         $i++;
  32.         }
  33.         ?>
  34.         <?php
  35.         if ($numRows%3 > 0){
  36.         ?>
  37.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  38.         <?php
  39.         }
  40.         ?>
  41.     </tr>
  42. </table>
Again i must say the code may need a spot of debugging.
hi.. i've tried the codes you've given me.. the first one still displays the images like this:
Expand|Select|Wrap|Line Numbers
  1. #
  2. #
  3. #
  4. #
  5. #
the 2nd one is the one that i need but there's something wrong, the first row has only 1 image but the succeeding rows are fine.. it displays like this:
Expand|Select|Wrap|Line Numbers
  1. #
  2. # # #
  3. # # #
  4. # # #
where's the problem with the code?
and where can i put this code

<td><center><?php echo mysql_result($rsPix,$i,"title"); ?></center></td>

so that the image has a title under it?
thanks again for the reply..
Feb 11 '08 #15
harshmaul
490 Expert 256MB
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...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.         $i++;
  25.             if ($i%3 == 0){
  26.         ?>
  27.     </tr><tr>
  28.             <?php
  29.             }
  30.         ?>
  31.         <?php
  32.  
  33.         }
  34.         ?>
  35.         <?php
  36.         if ($numRows%3 > 0){
  37.         ?>
  38.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  39.         <?php
  40.         }
  41.         ?>
  42.     </tr>
  43. </table>
i've moved the increment before the if statement.
Feb 11 '08 #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...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root",""))
  4.     {
  5.         $errmsg = "Cannot connect to database";
  6.     }
  7.  
  8. @mysql_select_db("upload");
  9.  
  10. $strSQL = "select * from pix";
  11. $rsPix = mysql_query($strSQL);
  12. $numRows = mysql_numrows($rsPix);
  13. $i = 0;
  14. ?>
  15. <table>
  16.     <tr>
  17.         <?php
  18.         while($i < $numRows){
  19.         ?>
  20.             <td>
  21.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  22.             </td>
  23.         <?php
  24.         $i++;
  25.             if ($i%3 == 0){
  26.         ?>
  27.     </tr><tr>
  28.             <?php
  29.             }
  30.         ?>
  31.         <?php
  32.  
  33.         }
  34.         ?>
  35.         <?php
  36.         if ($numRows%3 > 0){
  37.         ?>
  38.             <td colspan="<?php echo $numRows%3; ?>">&nbsp;</td>
  39.         <?php
  40.         }
  41.         ?>
  42.     </tr>
  43. </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..
Feb 12 '08 #17
harshmaul
490 Expert 256MB
Hi again,
I'm getting excited its almost done!!!

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


Expand|Select|Wrap|Line Numbers
  1.             <td>
  2.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
  4.             </td>
If this will do excellent, and if not i do have another solution but thats gonna take a while to code out.
Feb 12 '08 #18
Hi again,
I'm getting excited its almost done!!!

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


Expand|Select|Wrap|Line Numbers
  1.             <td>
  2.             <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <?php echo mysql_result($rsPix,$i,"pixTitle"); ?>"/>
  4.             </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!!
Feb 13 '08 #19
harshmaul
490 Expert 256MB
No problems mate, i like helping! (keeps me sane)
Feb 13 '08 #20
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:
Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <center><img src="pix.php?pid=<?php echo mysql_result($rsPix,$i,"pid"); ?>"/></center><br/>
  3. <center><a href = "<?php echo mysql_result($rsPix,$i,"title") . \".php\"; ?>"><?php echo mysql_result($rsPix,$i,"title"); ?></a></center>
  4. </td>
Feb 16 '08 #21
harshmaul
490 Expert 256MB
Hi again mate,

Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
  4. </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?
Feb 16 '08 #22
Hi again mate,

Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
  4. </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..
Feb 17 '08 #23
Hi again mate,

Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/><br/>
  3. <a href="<?php echo mysql_result($rsPix,$i,"pixTitle"); ?>.php"/>View details for <?php echo mysql_result($rsPix,$i,"pixTitle"); ?></a>
  4. </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..
Feb 17 '08 #24
harshmaul
490 Expert 256MB
Hi again,

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


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

Expand|Select|Wrap|Line Numbers
  1. <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....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $pixID = $_GET['pixID'];
  3. //A bit of DB logic here to get the record from the DB using $pixID
  4. $strSQL = "SELECT * FROM tblPix";
  5. $strSQL .= " WHERE pixID = $pixID";
  6. $rsPIX = mysql_query($strSQL);
  7. $num=mysql_numrows($rsPIX);
  8. $i=0;
  9.  
  10. if ($num < 0){
  11. $title = mysql_result($rsPIX,$i,"pixTitle");
  12. $description = mysql_result($rsPIX,$i,"pixDescription");
  13. }
  14. //Now you can print out the two variables there in the page containing the Title and Description.
  15. //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!
  16. ?>

I hope that makes sense
Feb 17 '08 #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...

Expand|Select|Wrap|Line Numbers
  1. <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....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $pixID = $_GET['pixID'];
  3. //A bit of DB logic here to get the record from the DB using $pixID
  4. $strSQL = "SELECT * FROM tblPix";
  5. $strSQL .= " WHERE pixID = $pixID";
  6. $rsPIX = mysql_query($strSQL);
  7. $num=mysql_numrows($rsPIX);
  8. $i=0;
  9.  
  10. if ($num < 0){
  11. $title = mysql_result($rsPIX,$i,"pixTitle");
  12. $description = mysql_result($rsPIX,$i,"pixDescription");
  13. }
  14. //Now you can print out the two variables there in the page containing the Title and Description.
  15. //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!
  16. ?>

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?
Feb 18 '08 #26
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..
Feb 18 '08 #27
harshmaul
490 Expert 256MB
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="imageDetails.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" (in my instance called imageDetails.php) do something like this....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $pixID = $_GET['pixID'];
  3. //A bit of DB logic here to get the record from the DB using $pixID
  4. $strSQL = "SELECT * FROM tblPix";
  5. $strSQL .= " WHERE pixID = $pixID";
  6. $rsPIX = mysql_query($strSQL);
  7. $num=mysql_numrows($rsPIX);
  8. $i=0;
  9.  
  10. if ($num < 0){
  11. $title = mysql_result($rsPIX,$i,"pixTitle");
  12. $description = mysql_result($rsPIX,$i,"pixDescription");
  13. }
  14. //Now you can print out the two variables there in the page containing the Title and Description.
  15. //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!
  16. ?>
Feb 18 '08 #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="imageDetails.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" (in my instance called imageDetails.php) 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($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!
?>
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..
Feb 22 '08 #29
harshmaul
490 Expert 256MB
okies, i never read that.

can you post some mark up this time.

Also your table definition would help
Feb 22 '08 #30
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..
Feb 23 '08 #31
harshmaul
490 Expert 256MB
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.....


Expand|Select|Wrap|Line Numbers
  1. <?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
Feb 23 '08 #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.....


Expand|Select|Wrap|Line Numbers
  1. <?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..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root","")) {
  4.         $errmsg = "Cannot connect to database";
  5.         }
  6. @mysql_select_db("upload");
  7.  
  8. $pid = $_GET['pid'];
  9. $strSQL = "SELECT * FROM sharp where (pid = '$pid')";
  10.  
  11. $rsPIX = mysql_query($strSQL);
  12. $num=mysql_numrows($rsPIX);
  13. $i=0;
  14.  
  15. if ($num > 0){
  16. $title = mysql_result($rsPIX,$i,"title");
  17. $description = nl2br(mysql_result($rsPIX,$i,"feature"));
  18. }
  19. echo $title . "<br>";
  20.  
  21. echo $description . "<br>";
  22. ?>
Feb 24 '08 #33
harshmaul
490 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errmsg = "";
  3. if (! @mysql_connect("localhost","root","")) {
  4.         $errmsg = "Cannot connect to database";
  5.         }
  6. @mysql_select_db("upload");
  7.  
  8. $pid = $_GET['pid'];
  9. $strSQL = "SELECT * FROM sharp where (pid = '$pid')";
  10.  
  11. $rsPIX = mysql_query($strSQL);
  12. $num=mysql_numrows($rsPIX);
  13. $i=0;
  14.  
  15. if ($num > 0){
  16. $title = mysql_result($rsPIX,$i,"title");
  17. $description = nl2br(mysql_result($rsPIX,$i,"feature"));
  18. }
  19. echo $title . "<br>";
  20.  
  21. echo $description . "<br>";
  22. ?>

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....

Expand|Select|Wrap|Line Numbers
  1. <img src="pix.php?pixID=<?php echo mysql_result($rsPIX,$i,"PixID"); ?>"/>
Put that in the if statement and it should work!
Feb 24 '08 #34
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....

Expand|Select|Wrap|Line Numbers
  1. <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?
Feb 24 '08 #35
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*
Feb 26 '08 #36
Markus
6,050 Expert 4TB
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?
Feb 26 '08 #37
harshmaul
490 Expert 256MB
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
Feb 26 '08 #38
Are you not able to store images on the server?
the images are only stored in the DB..
Feb 27 '08 #39
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..
Feb 27 '08 #40
harshmaul
490 Expert 256MB
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.
Feb 27 '08 #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.
would there be a problem if i export/import it from one pc to another?
Feb 28 '08 #42
harshmaul
490 Expert 256MB
How much space worth of images are you likely to save in the DB?

is it a commercial project, uni project?
Feb 28 '08 #43
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...
Feb 28 '08 #44
harshmaul
490 Expert 256MB
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
Feb 28 '08 #45
nse111
21
OMG!! I'v bin lookin for this for sooooooooooo long! all of u r life savers!!!!! thaaaaaaaaaaaaaaaaaaaaanks!!! I'm a newbie myself :( thanks thanks... :)
Aug 5 '08 #46
Hey everyone...

I've tried following this thread, and can't seem to get the code to work! I've been working on this for hours now, and i'm going crazy here lol

When I go to test2.php (which should show me the images), all it shows are image placeholders! It's pulling the images somewhat correctly, if I upload another image to the table...it'll show another placeholder, and viewing properties on the images shows the correct URL...the image just isn't showing up at all :( Can anyone help?

Here's my code:

test.php
Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.     $errmsg = "";
  3.     if (! @mysql_connect("localhost","root","welcome"))
  4.     {
  5.     $errmsg = "Cannot connect to database";
  6.     }
  7.     @mysql_select_db("emotion");
  8.  
  9.     if (IsSet($_GET['image_id'])){
  10.    $gotten = @mysql_query("select image, type from whats_hot where image_id = ".$_GET['image_id']);
  11.    list( $type,$data ) = mysql_fetch_row( $query );
  12.    header("Content-type: {$type}");
  13.    while ($row = mysql_fetch_array($gotten,MYSQL_ASSOC))
  14.    {
  15.    print $row['image'];
  16.  
  17.    }
  18.    mysql_free_result($gotten);
  19.    }
  20.    ?>
test2.php
Expand|Select|Wrap|Line Numbers
  1.  
  2.    <?php
  3.    $errmsg = "";
  4.    if (! @mysql_connect("localhost","root","welcome"))
  5.    {
  6.    $errmsg = "Cannot connect to database";
  7.    }
  8.    @mysql_select_db("emotion");
  9.  
  10.    $strSQL = "select * from whats_hot";
  11.    $rsPix = mysql_query($strSQL);
  12.    $numRows = mysql_numrows($rsPix);
  13.    $i = 0;
  14.  
  15.    while($i < $numRows){
  16.    ?>
  17.    <img src="test.php?image_id=<?php echo mysql_result($rsPix,$i,"image_id"); ?>"/>
  18.    <?php
  19.    $i++;
  20.    }
  21.    ?>
  22.  
  23.  
my whats_hot table is set up like so:

image_id (int) auto_increment
image (MEDIUMBLOB)
type (varchar)
Jan 16 '09 #47
tharden3
916 512MB
@harshmaul
This page has a lot of great information, and I'm glad Bytes has such active and helpful members. I'm a bit confused though. I was wondering if you could help me out.

I'm trying to achieve basically the same thing that these two pages (pix.php and list.php) seek to create. I'd like to take the images from a database, and show those images to my website users in a nice neat little column. You don't need to show me any code, you've already done that. I just have a few questions.

So the first thing I need to do is set up my tables with a BLOB field labeled imgdata, and a pixID field labeled..... well, what exactly is the pixID field, and how should it be labeled? What are the signifigance of each of these pages? Which part of the code am I just referencing to, and which part actually shows the image? I'd just like a little clarification. I'm awfully new to this. Thanks Bytes.

-Tim
Feb 3 '09 #48
Hi everyone,

I tried to make this to work but I am having the same problem as vinco83. The images seems to get retrived correctly but it only shows the placholder not image. when I debugged it says that "ID not found in Msyql result index 5"

Looking forward to hear from you soon !


Best regards,
Naim
Feb 7 '12 #49

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

Similar topics

1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
2
by: RedSouljaz | last post by:
Hi, How to display image that was saved in database ms sql server 2000 into picture box. The field type that I use in database is Images I can save to database but cannot show from database. ...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
1
by: shalini328 | last post by:
I am using ASP.net 1.1 C# and database is MS access.Can you tell me how can i display image from database
1
by: saadkhan | last post by:
I want to display image in <img> tag using database. I just need to know that how could i be able to define path or whatever to <img> tag. I have no probem in making queries to database.....plz help
5
by: SafaaDalloul | last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
1
by: Laxmikant | last post by:
I am using VB6 as front end, Access 2007 as backend, crystal report 8 for reporting. I want to display image on my crystal report output, based on path saved in a table in Access Database. Is it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.