www.webdeveloper.com
Results 1 to 2 of 2

Thread: [img tag] [do while] My code cannot run correctly

  1. #1
    Join Date
    Oct 2012
    Posts
    2

    [img tag] [do while] My code cannot run correctly

    Hi, I am a newbie to php.

    I would like to make a php page to show 5 identical image in a row. As following:


    But my code doesn't work

    PHP Code:
    <?
    $ImageNumber
    =5;
    do{
        --
    $ImageNumber;
        echo 
    "<img src="Image.png" width:"30px";>"
    } while ($ImageNumber<=0);
    ?>
    Thanks for any advice!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,227
    As far as the line that echoes out the img tag, you have several problems:
    1. If you are going to wrap a string literal in double quotes, then any literal double quotes within it must be escaped with a back-slash.
    2. Looks like you want a style attribute for the width?
    3. You need a semi-colon that at the end of the line.
    PHP Code:
    echo "<img src=\"Image.png\" style=\"width:30px;\">"
    Alternatively, just use one type of quote to delimit the string literal and the other for literal quotes within the string:
    PHP Code:
    echo "<img src='Image.png' style='width:30px;'>"
    Or in this case, since you aren't really using any PHP functionality in that string, just exit out of PHP mode (and also fix your comparison logic!):
    PHP Code:
    <?php
    $ImageNumber
    =5;
    do{
        --
    $ImageNumber;
    ?>
    <img src="Image.png" style="width:30px;">"
    <?php
    } while ($ImageNumber>=0);
    ?>
    (I strongly recommend the use of the full <?php tag, as short_open_tags may not always be enabled, and it avoids conflict with "<?xml" tags.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles