Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 22
  1. #1
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Ok I have a question. Does any1 know what code to write to have an image appear if the value is set to 1, but if it is set to 0 it is left blank?

    I hope some1 understands what I am tryin to say I know sometimes I dont.

    Anything you can tell me would be greatly appreciated.

    THANKS!
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey.

    This code will show image.jpg if $show_image is set to 1.
    If not, blank.jpg will be shown instead

    PHP Code:
    <?php

    $show_image 
    1;

    if(
    $show_image == 1) {
    ?>
    <img src="image.jpg" width="50" height="50" alt="alternate text" />
    <?php
    } else {
    ?>
    <img src="blank.jpg" width="50" height="50" alt="alternate text" />
    <?php
    }
    ?>

  4. #3
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Thanks for the help!
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    And, for the sake of being all C-like, you can actually use `if ( $show_image )' instead of `if ( $show_image == 1 )'. It's a shorthand that works in this case, but be careful where you use it.

  6. #5
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    ok Heres what I put and it doesnt do too well.

    What am I doin wrong here?

    PHP Code:
    $row[explicit] = 1;


    if (
    $row[explicit]== ) {
    echo \
    "<img src=\"images/layout/explicit_lyrics_th.gif\" width=\"56\" height=\"40\" />\";
    } else {
    echo \"<img src=\"images/layout/wedge.gif\" width=\"56\" height=\"40\" />\";


    Heres the link to the page: www.localamp.com/list.php

    What wrong here?
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  7. #6
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    So that you do not have to escape the " you could use ' instead.

    PHP Code:
    $show_image 1;
    if (
    $show_image == 1) {
    echo 
    '<img src="images/layout/explicit_lyrics_th.gif" width="56" height="40" />';
    } else {
    echo 
    '<img src="images/layout/wedge.gif" width="56" height="40" />';

    I created a file on my space with that code, and the output was
    PHP Code:
    <img src="images/layout/explicit_lyrics_th.gif" width="56" height="40" /> 
    Hope that helps.

  8. #7
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Um. That didnt change the error when I switched the " for the ' but it still is like that. I even took out == 1 but nothing.

    Any other suggestions?
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  9. #8
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I think it has to do with the variable your checking against, $row[explicit]

    Try this exact code:
    PHP Code:
    <?php
    $show_image 
    1;
    if (
    $show_image == 1) {
    echo 
    '<img src="images/layout/explicit_lyrics_th.gif" width="56" height="40" />';
    } else {
    echo 
    '<img src="images/layout/wedge.gif" width="56" height="40" />';
    }
    ?>
    Or, see my demo.

  10. #9
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Ok. I put in that code. It doesnt have any errors but theres no images either.

    How am I suppose to check the columnname explicit if its not put in the code?

    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  11. #10
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Dude theres no images as I have not uploaded your images to my space.

    So, are you wanting to retrieve the value from a database and then show the image or not show it depending on it's value?


Page 1 of 3 1 2 3 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:51 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com