SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    return results of a query

    I'm trying to display the results of a query using the following code.
    PHP Code:
    $query "SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = '$Email'";
    $handle mysql_query($query) or die("Error: " mysql_error()); //Do the query
    echo $handle;
    while(
    $row mysql_fetch_array($handle)){
    $thumb_name $row['thumb_name'];
    $photo_name $row['photo_name'];
    echo 
    '<img src="/images/ASP_Images/Thumbnail/"'.$thumb_name.'" />';

    But when I run the code, I get
    Resource id #5
    and no images?
    Why does the while loop not run?
    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe the query didnt return any results. try the query in phpmyadmin or somethign to make sure it has results

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    If I echo the query, I get
    SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = 'jon@test.com'
    and if I paste it into mysql I get 3 results (see screenshot)
    Attached Images Attached Images
    Last edited by lukeurtnowski; Dec 16, 2008 at 22:42.
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Remove this line:
    echo $handle;

  5. #5
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you view source and see if maybe the images are just invalid

  6. #6
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    When I view source, I get
    <fieldset style="clear:both">
    <legend>Images</legend>
    Resource id #5</fieldset>
    So its not even seeing the loop
    http://www.houstonasp.com/php/show_provider.php?ID=3
    Last edited by lukeurtnowski; Dec 17, 2008 at 01:19.
    "Oh, and Jenkins--apparently your mother died this morning."

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the following code output?

    PHP Code:
    $query "SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = '$Email'";
    $handle mysql_query($query) or die("Error: " mysql_error()); //Do the query
    $row mysql_fetch_array($handle);
    echo 
    '<pre>';
    print_r($row); 

  8. #8
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    next thing i woudl do is check mysql_num_rows() to make sure the query is getting results

  9. #9
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I'm so confused, I checked mysql_num_rows()
    PHP Code:
    $sql "SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = '$Email'";
    $handle mysql_query($sql) or die("Error: " mysql_error()); //Do the query
    $row mysql_fetch_array($handle);
    echo 
    mysql_num_rows($handle);
    echo 
    '<pre>';
    print_r($row); 
    And it returns 0 (but I ran the query in PHPMyAdmin and it produces 3 results.. see screenshot)
    "Oh, and Jenkins--apparently your mother died this morning."

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding the pointer to your MySQL connect resource as a second parameter in your mysql_query() function call.

    i.e. $handle = mysql_query($sql,$dbconn);

    Where $dbconn is your database connection resource, obviously.

  11. #11
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query "SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = '$Email'";
    $handle mysql_query($query) or die("Error: " mysql_error()); //Do the query
    echo $handle;
    while(
    $row mysql_fetch_array($handle)){
    $thumb_name $row['thumb_name'];
    $photo_name $row['photo_name'];
    echo 
    '<img src="/images/ASP_Images/Thumbnail/".$thumb_name." />';

    Assuming you already made a proper connection

    Change to:
    PHP Code:
    $query "SELECT FROM PHOTO WHERE Email = '$Email'";
    $handle mysql_query($query) or die("Error: " mysql_error()); //Do the query
    while($row mysql_fetch_array($handle)){
    $thumb_name $row['thumb_name'];
    $photo_name $row['photo_name'];
    echo 
    '<img src="/images/ASP_Images/Thumbnail/"'.$thumb_name.'" />';

    Although you don't need Email = '$Email' because you have it stored already. You could simply just do:

    SELECT FROM PHOTO

    and for your loop, you could do

    $thumb_name = $row['thumb_name'];
    $photo_name = $row['photo_name'];
    $email = $row['Email'];

    Now you can use the variable $email to display the assigned email for each row.

  12. #12
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    k, ill try
    "Oh, and Jenkins--apparently your mother died this morning."

  13. #13
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I get

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM PHOTO' at line 1
    "Oh, and Jenkins--apparently your mother died this morning."

  14. #14
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You gave him a query with no select...

    luke: Can you post your full code and I'll help you?
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  15. #15
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query = "SELECT * FROM PHOTO WHERE Email = '$Email'";

  16. #16
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Oh, I got it, I accidentally changed the value of $Email.
    Thanks for the help.
    (I Used)
    $query = "SELECT thumb_name, photo_name, Email FROM PHOTO WHERE Email = '$Email'";
    $handle = mysql_query($query) or die("Error: " . mysql_error()); //Do the query
    while($row = mysql_fetch_array($handle)){
    $thumb_name = $row['thumb_name'];
    $photo_name = $row['photo_name'];
    echo
    '<img src="/images/ASP_Images/Thumbnail/".$thumb_name." />';
    }
    but added some code (the lightbox effect)
    Last edited by lukeurtnowski; Dec 18, 2008 at 13:40.
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •