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

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    Can anyone help a new PHP user?

    I'm constructing a search on a MySQL database.

    I have a field for thumbnail pictures, (picthumb)
    but some of the entries don't have thumbnail pictures.

    What I want is that when searching, if the thumbnail field is empty,
    then the resulting html page pulls up an image called coming.gif
    (which shows that the thumbnail is not yet available)

    I'm sure this is a simple if - else line, but I can't get it right.

    any help would be appreciated!
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Do it in your query:

    select foo,bar,if(isnull(thumb),'coming.jpg',thumb) as thumb from table....;

    Assuming the field name is 'thumb' and that you are storing the actual filename.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    Thanks Rod, but I don't seem to be able to get it working, have I got it in the right place?
    Here's the script.
    BTW the field is named (picthumb)

    $result = mysql_query ("SELECT * FROM propdata1 WHERE location LIKE '$location%' AND rental LIKE '$rental%' AND purchase LIKE '$purchase%' ");

    if(isnull(picthumb),'coming.gif',picthumb);
    if ($row = mysql_fetch_array($result)) {

    do {
    printf ("<body bgcolor=#FFFFFF>");
    printf ("<center><P><table border=0 cellpadding=5 cellspacing=0 width=600>n");
    printf ("<tr><td colspan=2>n");
    printf ("<strong>n");
    printf (" %sn",$row["name"]);
    printf (" - ");
    printf (" %sn",$row["location"]);
    printf ("</td></tr><tr><td>");
    printf ("</strong><br>");
    printf ("<img src=http://www.blah.com/img/");
    printf ($row["picthumb"]);
    printf ("</td></tr>n");
    printf ("</table></P></center>n");
    } while($row = mysql_fetch_array($result));
    } else {print "<br><br><center><b> Sorry, no records were found! </b></center>";}


    [This message has been edited by Mike Paxman (edited October 10, 2000).]
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You can do it in your query or outside. The code I gave you was for inside the query. To do it the way you are trying:

    <code>$result = mysql_query ("SELECT * FROM propdata1 WHERE location LIKE '$location%' AND rental LIKE '$rental%' AND purchase LIKE '$purchase%' ");


    if ($row = mysql_fetch_array($result)) {
    if $row[picthumb]=="" $row[picthumb]='coming.jpg';

    do {
    printf ("<body bgcolor=#FFFFFF>");
    printf ("<center><P><table border=0 cellpadding=5 cellspacing=0 width=600>n");
    printf ("<tr><td colspan=2>n");
    printf ("<strong>n");
    printf (" %sn",$row["name"]);
    printf (" - ");
    printf (" %sn",$row["location"]);
    printf ("</td></tr><tr><td>");
    printf ("</strong><br>");
    printf ("<img src=http://www.blah.com/img/");
    printf ($row["picthumb"]);
    printf ("</td></tr>n");
    printf ("</table></P></center>n");
    } while($row = mysql_fetch_array($result));
    } else {print "<br><br><center><b> Sorry, no records were found! </b></center>";}</code>

  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    The middle line here is throwing a parse error:

    if ($row = mysql_fetch_array($result));{
    if $row[picthumb]=="" $row[picthumb]='coming.gif';
    do {
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Remove the ; from between the first if and the opening {
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    I've already done that, but I still get a

    Parse error: parse error, expecting `'(''

  14. #8
  15. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Doh! Forgot the parenthesis.

    if ($row[picthumb]=="") $row[picthumb]='coming.jpg';
  16. #9
  17. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,643
    Rep Power
    4492
    You could also set a default in your table, so instead of storing NULL it will store 'coming.jpg' Then there won't be any additional logic you have to do

    You can use the alter command to change it.

    ALTER TABLE your_table CHANGE COLUMN your_column_name new_column_name VARCHAR(50) DEFAULT 'coming.jpg';

    I'm assuming it's a varchar column, adapt to your needs. Also, have the two column names be the same if you don't want to change the name.

    It's another approach...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    Thanks for the help! Problem solved.

Similar Threads

  1. Replies: 2
    Last Post: January 28th, 2004, 07:07 AM
  2. ORDER BY and empty fields
    By dimitrisk in forum MySQL Help
    Replies: 2
    Last Post: January 27th, 2004, 12:29 PM
  3. MS SQL equivalent of MS Access lookup fields
    By squawk in forum MS SQL Development
    Replies: 3
    Last Post: January 9th, 2004, 03:30 PM
  4. Replies: 4
    Last Post: December 22nd, 2003, 07:12 PM
  5. Replies: 1
    Last Post: December 19th, 2003, 10:12 AM

IMN logo majestic logo threadwatch logo seochat tools logo