SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Plain HTML inside while loop...

    Hi, I want to put a mix of PHP & HTML in a while loop.

    while ($row = mysql_fetch_array($result))
    {
    // Tons of HTML and PHP codes...
    }

    Is there anything like a ENDWHILE similar to ENDIF in PHP? I don't want to rewrite everything inside the loop to fit PHP syntax...

    Thanks again...

  2. #2
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while ($row = mysql_fetch_array($result))
    {
    if($blah = wibble){
    ?>
    HTML CODE
    <?
    }
    }

    you dont have to mess about changing any code

  3. #3
    SitePoint Zealot infoxicated's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $blah will always equal $wibble in the example above.

    if ($blah == $wibble) would be more correct!

  4. #4
    SitePoint Evangelist galt's Avatar
    Join Date
    Apr 2002
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what PHP is all about jump out jump in jump out jump in.

    The fact that you can switch modes in the middle of a statement is just so cool.

    <h1><?php echo $title ?> </h1>

    is just as legal as

    <?php
    echo '<h1>';
    echo $title;
    echo '</h1>';
    ?>

    or even

    <?php
    echo '<h1>' . $title . '<h2>';
    ?>

    Jumping out in the middle of an IF control block like gryff's example is VERY nice too, just make sure your code is readable.


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
  •