#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    2
    Rep Power
    0
    I have a database which when queried brings back results one of which is an image name. The image name points to a subdirectory to display the image. Everything works fine but if there is no image name then the image is not found (obviously). How can I tell a result to not show the entry if it's empty?

    The code goes something like this

    mysql_select_db($databaseName,$db);

    $result = mysql_query("SELECT * FROM reports WHERE target_page LIKE 'News' ORDER BY description",$db);

    if ($myrow = mysql_fetch_array($result)) {

    echo "
    <table border=0 width=70%>n"; do { echo "
    <tr>
    n"; printf("
    <td><B>%s</B></td>
    </tr>n", $myrow["description"]); echo "
    <tr>
    n"; printf("
    <td>%s</td>
    </tr>n", $myrow["paragraph_1"]); echo "
    <tr>
    n"; printf("
    <td>%s</td>
    </tr>n", $myrow["paragraph_2"]); echo "
    <tr>
    n"; printf("
    <td><IMG SRC=%s></td>
    </tr>n", $myrow["image"]); echo "
    n"; printf("

    </tr>n", $myrow[""]); } while ($myrow = mysql_fetch_array($result)); echo "
    </table>n"; } else { echo "Sorry, no records were found!"; } ?>

    Any help would be appreciated
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    15
    Just a quickie responce.

    This may apply to your situation. I have a page that lists entered info. followed by the words "Email" and "Web Page" which links to their emai and url. If none are entered I want it left blank. The code below does the trick. I place it right before the printf( ) line. Hope it helps.
    ********************

    if ($myrow["email"] != "")
    {
    $email = sprintf("<a href="mailto:%s">Email</a>", $myrow["email"]);
    }else
    {$email = "";
    }
    if ($myrow["url"] != "")
    {
    $url = sprintf("<a href="%s">Web Site</a>", $myrow["url"]);
    }else
    {$url = "";
    }
    printf( .......

    ***************************
    good luck

    stujo
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    Yea,

    just put a 'if' condition in you do..while loop for getting desired result..


    mysql_select_db($databaseName,$db);

    $result = mysql_query("SELECT * FROM reports WHERE target_page LIKE 'News' ORDER BY description",$db);

    if ($myrow = mysql_fetch_array($result)) {

    echo "<table border=0 width=70%>n";
    do {

    if(!empty($myrow["image"])){
    //if the image field is not empty then print the result other wise no..

    echo "<tr>n";
    printf("<td><B>%s</B></td></tr>n", $myrow["description"]);
    echo "<tr>n";
    printf("<td>%s</td></tr>n", $myrow["paragraph_1"]);
    echo "<tr>n";
    printf("<td>%s</td></tr>n", $myrow["paragraph_2"]);
    echo "<tr>n";
    printf("<td><IMG SRC=%s></td></tr>n", $myrow["image"]);
    echo "n";
    printf("</tr>n", $myrow[""]);

    }

    }while($myrow = mysql_fetch_array($result));
    echo "</table>n";
    }else {
    echo "Sorry, no records were found!";
    }
    ?>



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    2
    Rep Power
    0
    Thanks very much. Both examples solve my problem. As happens many times once someone shows you that you could do it "this way" it all falls into place.

    Thanks again

    Bob Mallett

Similar Threads

  1. Replies: 1
    Last Post: February 6th, 2004, 06:53 AM
  2. Inserting from form to multiple tables
    By barth in forum MySQL Help
    Replies: 0
    Last Post: January 25th, 2004, 10:27 AM
  3. put variable in text field
    By alexmasters in forum PHP Development
    Replies: 3
    Last Post: January 14th, 2004, 08:32 PM
  4. cgi.pm module not compatible with multipart enctype syntax
    By Suzette in forum Perl Programming
    Replies: 2
    Last Post: December 22nd, 2003, 12:19 PM
  5. return value from 3 fields into 1 field
    By denali in forum MS SQL Development
    Replies: 1
    Last Post: December 19th, 2003, 08:44 AM

IMN logo majestic logo threadwatch logo seochat tools logo