SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: View image

  1. #1
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    View image

    Greetings!

    I heard that it's not a good practice to save the image itself in the database, so I did is to save the file name and it's size at the same time, the actual image will save in a folder I call 'images', and I did it working. The problem is the image is not working properly when showing, the result is a torn paper icon.

    below are my codes.

    Code:
    $show  = mysql_query ("SELECT  MAX(id) AS mid FROM upload ") or die (mysql_error());
    				while ($row=mysql_fetch_array ($show))
    				{
    				echo $row['mid']."<br/>";
    				echo "<img src = 'images/".$row['mid'].">";
    I tried to get the source code to display the name that matched in my query.
    Any help would be appreciated.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    From the query, it looks like you're selecting an ID, not a filename. I think you need to rethink your query.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    thank you for your quick response. I change already, I can see now my filename, but still I got the same icon.

    Code:
    $show  = mysql_query ("SELECT  name FROM upload ") or die (mysql_error());
    				while ($row=mysql_fetch_array ($show))
    				{
    				echo $row['name']."<br/>";
    				echo "<img src = 'images/".$row['name'].">";
    				
    				}

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    There's an error in your HTML output (the image tag is incorrect, too many spaces in the src attribute and you're missing a closing quote), try this:

    PHP Code:
    $show  mysql_query ("SELECT  name FROM upload ") or die (mysql_error());
    while (
    $row=mysql_fetch_array ($show))
    {
        echo 
    $row['name']."<br/>";
        echo 
    '<img src="images/'.$row['name'].'">';


  5. #5
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Immerse View Post
    too many spaces in the src attribute and you're missing a closing quote
    Having spaces in the src attribute is not an issue.

    This works fine, although I wouldn't normally have the additional spaces.

    Code:
    <img src = "pic1.jpg" alt="" />
    @OP

    you can normally fix problems like in your post fairly quickly by looking at the actual html created by your php code. Run your php page in your browser and select 'View source' (or whatever your browser has) to see the actual html created by your php code. Then scroll to the problem area in your html to see what the problem is. Then fix your php code so that it creates the correct html.

  6. #6
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    thank you. I got it working already..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •