PHP syntax help

Discussion in 'PHP' started by deepman007, Mar 27, 2008.

  1. #1
    Hi

    I don't know why the thumb1.jpg and big1.jpg are not showing up.
    Here's the code:

    $imgNo =1;
    <?php echo '<li><img src="images/thumb"'.$imgNo.'".jpg" alt="White" title="RapperW" border="0" onclick="swap(\'largeid\',\'images/big$imgNo.jpg\');"/></li>'; ?>

    Any clues?
     
    deepman007, Mar 27, 2008 IP
  2. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i think you need to use " instead of ' for your string above, data inside ' doesn't get parsed, so it'd be ignoring the backslashed ' in your string because of it, using " will fixed that.
     
    powerspike, Mar 27, 2008 IP
  3. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What do you mean ?
     
    deepman007, Mar 27, 2008 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    Dunno about big1.jpg but the first one, you have it outputting something like thumb"1.jpg" which is wrong of course.

    $imgNo =1;
    <?php echo '<li><img src="images/thumb'.$imgNo.'.jpg" alt="White" title="RapperW" border="0"

    Should fix it.
    That of course assumes you have $imgNo1 inside the <?php tags.
     
    shallowink, Mar 27, 2008 IP
  5. AreaZeroOne

    AreaZeroOne Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    Try this:

    
    <?php
    
         echo "<li><img src=\"images/thumb/$imgNo.jpg\" alt=\"White\" title=\"RapperW\" border=\"0\" onclick=\"swap('largeid','images/big$imgNo.jpg');\"><li>";
    
    ?>
    
    Code (markup):
    That should do it. Make sure that second var gets parsed though (in the onclick). You might have to change the "" '' in there I think.
     
    AreaZeroOne, Mar 27, 2008 IP
  6. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Just curious, Whats the difference between single quote and double quote? I meant they both seems to work.
     
    deepman007, Mar 27, 2008 IP
  7. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    double quotes, php will parse double quotes, but won't parse single quotes.

    
    $var = "bob";
    print "$var";
    [/bob]
    you'll get "bob"
    [code]
    $var = "bob";
    print '$var';
    [/bob]
    will print out $var
    Code (markup):
     
    powerspike, Mar 28, 2008 IP
  8. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    <img src="images/thumb"'.$imgNo.'".jpg" ...etc.

    You are essentially printing <img src="images/thumb"1".jpg .....
     
    Gordaen, Mar 28, 2008 IP
  9. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php
    $imgNo =1;
    echo "<li><img src=\"images/thumb$imgNo.jpg\" alt=\"White\" title=\"RapperW\" border=\"0\" onclick=\"swap(\'largeid\',\'images/big$imgNo.jpg\');\"/></li>"; ?>



    I think this will help you just copy and paste it.......... :
     
    singh.ajit05, Mar 29, 2008 IP
  10. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just concatenate it:

    
    echo '<li><img src="images/thumb"' . $imgNo . '".jpg" alt="White" title="RapperW" border="0" onclick="swap(\'largeid\',\'images/big' . $imgNo . '.jpg\');"/></li>';
    
    PHP:
     
    Marc Fraser, Mar 29, 2008 IP
  11. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #11
    Example:

    $var = 'Hello';

    echo "$var world!";
    echo '$var world!';

    /* Theoretical fastest way */
    echo $var , ' world!';

    ?>

    Run to see the difference. Parses things such as \n, \r, \t and variables etc if it's IN double quotes, otherwise not.

    Dan
     
    Danltn, Mar 29, 2008 IP