#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80

    Displaying image from image path


    Trying to display this simple query. Everything works but i can't get the image path correct. Its just displaying the image name.
    PHP Code:
    while ($row mysql_fetch_array ($r)) { print "<p>{$row['title']} <br />
       
    {$row['address']} <br />
       
    {$row['description']} <br />
       
    {$row['price']} <br />
       <img src= "
    ./uploads/images".{$row[['images']}"/>  <br />
       {
    $row['contact']} <br />
       {
    $row['phone']} </p>"; 
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    24
    Can you print the output from the browser as well?

    I think the KEY lies in that output source :-)
    To err is human, to set_error_handler(), is divine...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80
    I got it fixed.
    <img src= '/uploads/images/{$row['images']}'> <br />

    Now I have a new issue. I want to only return results if one of the fields is not null. Such as is if there is a price, an image, description then display the results. I just can't figure it out.

    $query = 'SELECT * FROM phpbb_users WHERE price or image or description IS NOT NULL';
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    24
    Oh right!

    You need to escape your image location...

    because you use " for your string, you can not say

    $str = "<img src="theimage">";

    because it confuses the interpreter! Also, you broke and concatenated the string unnecessarily. Try this!

    PHP Code:
    while ($row mysql_fetch_array ($r)) { 

    print 
    "<p>{$row['title']} <br />
       
    {$row['address']} <br />
       
    {$row['description']} <br />
       
    {$row['price']} <br />
       <img src= \"./uploads/images"
    .{$row['images']}\"/>  <br />
       
    {$row['contact']} <br />
       
    {$row['phone']} </p>"
    Last edited by sp00nix; November 5th, 2007 at 08:49 PM.
    To err is human, to set_error_handler(), is divine...
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    24
    Originally Posted by mallen
    I got it fixed.
    <img src= '/uploads/images/{$row['images']}'> <br />

    Now I have a new issue. I want to only return results if one of the fields is not null. Such as is if there is a price, an image, description then display the results. I just can't figure it out.

    $query = 'SELECT * FROM phpbb_users WHERE price or image or description IS NOT NULL';
    So all three fields must not be null? If so, then you actually need the AND operator. When you describe the SQL requirement above it sounds like price, image, and description must not be null.

    But your SQL is the opposite, where basically its says:

    SELECT everything from users IF there is a price.... or there is an image... or there is a description which is not null...

    Did you mean:
    PHP Code:
    $query 'SELECT * FROM phpbb_users 
    WHERE price IS NOT NULL 
       AND image IS NOT NULL 
       AND description IS NOT NULL'

    To err is human, to set_error_handler(), is divine...
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80
    No. Some of the fields can be empty. If there is a price, or there is an image etc then display all the results of that record. Does that make sense?
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    24
    YES. You could do
    PHP Code:
    $query 'SELECT * FROM phpbb_users 
    WHERE price IS NOT NULL 
       OR image IS NOT NULL 
       OR description IS NOT NULL'

    To err is human, to set_error_handler(), is divine...
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80
    That didn't work. I either get all the records or none. Maybe I am confusing the term NULL with empty. Maybe my field in my database is not set right. They say NO in the Mysql database. maybe I should be checking for a value like "" for empty or zero
    Last edited by mallen; November 5th, 2007 at 09:28 PM.
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    24
    You you post a sample of a few entries from the DB?
    To err is human, to set_error_handler(), is divine...
  18. #10
  19. Expert Debugger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2006
    Location
    Dev Shed Forums (-_^)v
    Posts
    1,021
    Rep Power
    1306
    Try this :
    PHP Code:
    SELECT FROM phpbb_users 
    WHERE price 
    !='' 
       
    OR image !='' 
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80
    That didn't work either. Examples of the entries would be an image name like 12345.jpg, a price such as $120k, description, contact name. What I have is like 15 fields. I am only using (and displaying) the last few for people who have a property to sell. So if they are selling, they would have one of these fileds filled. So I only want to display records who are selling a property. I may have over 100 people in the database and only one person selling.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    459
    Rep Power
    80
    PHP Code:
    $query 'SELECT * FROM phpbb_users WHERE price != "" OR  images != "" OR description != ""'
    This worked. I was naming the images column wrong. I had it as "image" And I didn't have mysql_error() in the else statement telling me of the mistake. Thanks for all your help.

    Comments on this post

    • sarav_dude agrees : congrats !

IMN logo majestic logo threadwatch logo seochat tools logo