472,353 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to display image from mysql

selvasoft
i am doing a site for spinning mills
i need to display all the products that the company offers
Am using mysql database and word press (CMS)

i want to display my images with code number as like my attachment
Attached Images
File Type: jpg shade.jpg (11.9 KB, 593 views)
Mar 9 '10 #1
19 9101
Atli
5,058 Expert 4TB
Hey.

What have you done so far?
And what are you having trouble with?
Mar 9 '10 #2
i want to display my images with that code. and also i want upload tat scanned images in our database.that time i want group that image color vise.
Mar 9 '10 #3
hey
Am doing that manual not writing any queries
Mar 9 '10 #4
Atli
5,058 Expert 4TB
Ok. What have you done so far?

I don't know much about the specifics of WordPress, but I do know that in plain PHP this should be a simple matter of querying the data from the database, looping through the results and printing each one.

@selvasoft
What do you mean? If you plan on interacting with a MySQL database, you will have to write a few queries.
Mar 9 '10 #5
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $dbcnx = @mysql_connect("localhost", "root", "red");
  3.  
  4. if (!$dbcnx)
  5. {
  6. echo( "connection to database server failed!" );
  7. exit();
  8. }
  9.  
  10. if (! @mysql_select_db("my_db") )
  11. {
  12. echo( "Image Database Not Available!" );
  13. exit();
  14. }
  15.  
  16. $img = $_REQUEST["img"];
  17. $result = @mysql_query("SELECT * FROM images WHERE imgid=" . $img . "");
  18.  
  19. if (!$result)
  20. {
  21. echo("Error performing query: " . mysql_error() . "");
  22. exit();
  23. }
  24.  
  25. while ( $row = mysql_fetch_array($result) )
  26. {
  27. $imgid = $row["imgid"];
  28. }
  29.  
  30. echo base64_decode($encodeddata);
  31. ?>


this is not work what problem in that
Mar 9 '10 #6
Atli
5,058 Expert 4TB
I'm not surprised, seeing as this code was copy/pasted from an online tutorial (yes I can use Google too), one that was not meant to be put as-is into a working product. - It's meant to teach, not to be used.

You won't get a working solution by copy/paste alone. You need to actually know, or learn, PHP and MySQL to get this working. - And we will most certainly not be doing it for you.

If you want our help, tell us specifically what you are having trouble with. We aren't just going to take code you copied from some random tutorial and fix it up so you can copy it back into your project.
Mar 9 '10 #7
dear Atli

Please help me. When we want to display our images from database that time we start our script like
<img src="filename.php?id="imageid">
what is the use of this..
and where that image id will retrieve. I think that is our table id. is it correct or not.
Mar 10 '10 #8
Atli
5,058 Expert 4TB
The "imageid" there is the ID of an image from your database, which the "filename.php" script takes and retrieves, returning it to the <img>
Mar 10 '10 #9
i cant store my image to database
please check the following code is correct or not because that code did not return any
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $connection=mysql_connect("localhost","root","mypassword");
  3. if(!$connection)
  4. {
  5.  
  6. die('Not connect'.mysql_error());
  7. }
  8. // Create table
  9. mysql_select_db("my_db", $connection);
  10. $sql = "CREATE TABLE myimage
  11. (
  12. id int(5) NOT NULL auto_increment. ,
  13. image longblob NOT NULL,
  14. description char(50)
  15. )";
  16. mysql_query($sql,$connection);
  17. echo "table Created";
  18. mysql_select_db("my_db",$connection);
  19.  
  20.     $imgdata = file_get_contents($_FILES['fimage']['tmp_name']);
  21.     $fpo      = fopen($imgdata, 'r'); 
  22.     $imgdata1 = fread($fpo, filesize($imgdata));
  23.     $imgdata1 = mysql_real_escape_string($imgdata1 );
  24.  
  25. $sql = "INSERT INTO myimage (image,description) VALUES 
  26. ('$_POST['fdescription']','$imgdata1')";
  27. if (!mysql_query($sql,$connection))
  28. {
  29.  
  30.  die('Error'.mysql_error());
  31. }
  32. print ="Description;$fdescription";
  33. mysql_close($connection);
  34. ?>
Mar 10 '10 #10
Atli
5,058 Expert 4TB
What were you trying to achieve?
What exactly were you expecting it to return?
What did it actually return?
Did you get any errors?

What does the form that goes with this code look like?

And why are you so intent on putting the images into the database, rather than on the file-system?
Mar 10 '10 #11
Dear Atli

I have stored images in my database that will display in mysql as like my attachment.. here what is meaning [BLOB - 0 B].
There are 4 images were stored.
Attached Images
File Type: jpg blob.JPG (16.3 KB, 321 views)
Mar 10 '10 #12
Umm for one buddy your creating the table each time you run that script I'm surprised MySQL didn't kick you in the nads for that, if your going to do that at least use IF NOT EXISTS syntax so MySQL doesn't suffer.

Your reselecting the currently selected database, why?

In the SQL for CREATE TABLE why is there a period after auto_increment?

Why are you trying to open a string as a file?

I know PHP closes files automatically but you should still do it manually for good coding practice.

And
Expand|Select|Wrap|Line Numbers
  1. VALUES ('$_POST['fdescription']','$imgdata1')";
The variable should be enclosed with curly brackets
Expand|Select|Wrap|Line Numbers
  1. VALUES ('{$_POST['fdescription']}','$imgdata1')";
Also my best advice check out w3schools.com, tizag.com, and tutorialspoint.com and learn PHP before messing around with it especially before messing with files delete the wrong one and windows dies of course windows would reject your attempt ( or should ) but still bad idea.

Oh and if <img src="filename.php?id="imageid"> is actually your code check out w3school's excellent HTML tutorial while your there.

And one final person comment, where ever you found this tutorial don't go back there ... ever.

And I apologize if I was rude, but you need to understand PHP before jumping that far into it, believe me I know.
Mar 11 '10 #13
ok ok thanks for your comments.Now i have learned something about php.
Mar 12 '10 #14
hi philip

i have one question, i have more than one images in my mysql database.
i want to display all images color vise. when am selected color in my combo box drop down in my web page.
For Example i have selected red color means only display the images where the images name contain red.
Please find out my attachment. that is my web page.

Thank you
Attached Images
File Type: jpg select.JPG (5.0 KB, 255 views)
Mar 12 '10 #15
I'd say you'd need to add a "color" field to the MySQL table otherwise you'd have to do some pretty hardcore hacking on the images to get there overall color. Then just use a WHERE cause in the SQL "WHERE `color`='red'".
Mar 12 '10 #16
I have color field in my database. but i don't know how can i retrieve that values in my combo box.

Thank you
Mar 12 '10 #17
Please help me. I have color field in my database but i don't know how can i retrieve that colors in my combo box.
give any idea to me.

Thank you
Mar 12 '10 #18
Atli
5,058 Expert 4TB
It's fairly simple. You query the database for the colors, loop through them, and print each color as an <option> for your <select> box. - If you read through any one of the literally hundreds of beginner PHP/MySQL tutorials out there, this should be no problem.

Try it. If you run into problems, post them here. (With proper explanations!)
Mar 12 '10 #19
Ok thank you for your help. i will try that.
Mar 12 '10 #20

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

Similar topics

3
by: adam | last post by:
Hi, I have an issue that i just cant seem to figure out hope some one can help. right i am getting people to input the own images directly into a...
0
by: Dan Anderson | last post by:
I have created a BLOB field to store images. Is there any way to embed them within HTML with something like: <image start: jpeg> </image> ...
2
by: david | last post by:
Hi, I have asp pages running from a MySQL database. I have placed a path in the required field (although not quite sure on the correct format)....
1
by: davidgordon | last post by:
Hi, I have a form in which I need to display an image of our product. On our server is a folder which contains all the images. In our MySQL db...
1
by: Objectifnet | last post by:
What I really want to do is to be able to link two pages together using an ID, The table involved displays an image stored on the File Server that...
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...
4
by: tanyali | last post by:
my .png files r stored as a blob in MySql, I wanna to display them out in php through a web browser. this is part of code (in php): ---after...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0...
4
by: foss | last post by:
HI all, I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly . The code used for uploading...
6
by: msmjsuarez | last post by:
how can i display both image and other information in the web page using php? i'm using mysql database. I do displaying the image only but i want...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.