SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using AND or similar?

    I just wondered how I would write the following, I want to use "and" or the equivelent ( I have highlighted this part in bold) - What I'm trying to do is serve out a larger image (lgimage) if the smaller one is not present in the database (smimage) and if there is none of either then show a blank space I guess.

    Code:
    $smimage=$fetchm['smimage'];
    $lgeimage=$fetchm['lgimage'];
    
    if (!empty($smimage))
    $smimage=$fetchm['lgimage'];
    
    }
    else
    { 
    if (!empty($smimage)) and  (!empty($lgeimage)) 
    
    {
    echo "<td valign='top' style='border-width:1px; border-bottom-color:rgb(153,204,153); border-bottom-style:solid; padding:4px;'><img src='".$smimage."'></td>";
    }
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This doesn't work because you closed the parentheses that are supposed to wrap around the entire conditional. Here's your fix:
    PHP Code:
    if (!empty($smimage) && !empty($lgeimage)) 
    Yeah, I used '&&', I know - it's cuz I'm a C programmer. There's nothing wrong with using 'AND' in PHP, so if you prefer it then by all means don't let me stop you!
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok that was easy but I have another problem before this now....

    Parse error: parse error, unexpected T_ELSE in ...prod.php on line 89
    line 89 = else

    I guess it must be something with this part?

    Code:
    if (!empty($smimage))
    $smimage=$fetchm['lgimage'];
    
    }
    else
    {
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I think I worked that out but now when I run this it shows no images anymore? (no errors are reported)

    Code:
    $smimage=$fetchm['smimage'];
    $lgeimage=$fetchm['lgimage'];
    if(!empty($smimage))
    $smimage=$fetchm['lgimage'];
    else
    if (!empty($smimage) and !empty($lgeimage)) 
    {
    echo "<td valign='top' style='border-width:1px; border-bottom-color:rgb(153,204,153); border-bottom-style:solid; padding:4px;'><img src='".$smimage."'></td>";
    }
    ]
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (!empty($smimage))
    {
        
    $smimage=$fetchm['lgimage'];
    } else {
        if (!empty(
    $smimage) and !empty($lgeimage))
        {
            echo 
    "<td valign='top' style='border-width:1px; border-bottom-color:rgb(153,204,153); border-bottom-style:solid; padding:4px;'><img src='".$smimage."'></td>";
        }

    This is basic code encapsulation: any time you have multiple lines of code associated with a conditional, you must enclose them in brackets; often I enclose single lines as well for consistency. Every opened bracket must be closed; properly indenting your code and eliminating extraneous blank lines will make this easier to see and correct.
    PHP questions? RTFM
    MySQL questions? RTFM

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see thanks,

    it is nearly there but I still have a problem, I will explain it:

    first here is what I have ( I had to change it to use $lgeimage =='') instead of the other way for some reason?):

    Code:
    $blankImage = "blank.gif";
    
    $smimage=$fetchm['smimage'];
    $lgeimage=$fetchm['lgimage'];
    
    if ($smimage =='' and $lgeimage (IS THERE) '')
    {
        $smimage=$lgeimage;
    } else {
        if ($smimage =='' and $lgeimage =='')
        {
            $smimage=$blankImage;
        }
    }

    So all I need to do now is to know how to write the "(IS THERE) part - which is just a place holder for the correct code I would use?

    In other words I want to show the small image but if it's not there then show the large image but if both are not there then show the blank one.
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think tthis might be correct?

    if ($smimage =='' and $lgeimage =='True')
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    New Zealand
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($smimage == '')
    {
        if (
    $lgimage != '')
        {
            
    $smimage $lgimage;
        } else {
            
    $smimage $blankimage;
        }

    OR more compactly
    PHP Code:
    if ($smimage == '')
    {
        
    $smimage =  ($lgimage != '') ? $lgimage $blankimage;


  9. #9
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thats great, a lot more optimized
    ideas wanted for new domains
    rockjewelry.info | palmbuy.info


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
  •