Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    write long html code over and over

    Hey guys, now with PHP I could simply make a for loop and then stop the PHP code and put some HTML to write, then it will keep writing that HTML until the loop ends.

    Doesn't look like it works with ASP. I have the following code below, for each number in an array I need to have this code written onto the page with afew things changed to it.

    PHP Code:
    <div class="container">
        <
    form id="50">
            <
    div class="image_container background">
                <
    div style="text-align:center; font-size:12px;">image1</div>
                <
    div class="image" style="background-image:url(images/image7.JPG);"></div>
                <
    div class="selected_product" id="50_products"></div>
            </
    div>
            <
    div class="controls_container background">
                <
    span id="50_selected" style="font-size:20px;">KR</span>
                <
    class="sale_button arrow expandProducts">
                <
    span>
                    <
    div class="products">
                        <
    span onClick="changeProduct(this,'KR');updateProduct(this)">KR</span>
                        <
    span onClick="changeProduct(this,'LR');updateProduct(this)">LR</span>
                   </
    div>
                </
    span>
                </
    a>
                <
    hr />
                <
    span class="sale_button plus" id="50_plus" onClick="incDecSale(this,'increase');updateProduct(this)"></span>
                <
    input type="text" id="50_qty" readonly value="0"/>
                <
    span class="sale_button minus" id="50_minus"onClick="incDecSale(this,'decrease');updateProduct(this)"></span>
                <
    hr />
                <
    input type="text" id="50_total" readonly value="£0"/>
            </
    div>
        </
    form>
    </
    div
    What would the best way of doing this be? I did try and make a long string, but for some reason that isn't working properly, I will put that below, bare in mind I didn't get around to replacing parts of the string with the variables.

    PHP Code:
    html "<div class=""""container"""">"
    html html "<form id=""""50"""">"
    html html "<div class=""""image_container background"""">"
    html html "<div style=""""text-align:center; font-size:12px;"""">image1</div>"
    html html "<div class=""""image"""" style=""""background-image:url(images/image7.JPG);""""></div>"
    html html "<div class=""""selected_product"""" id=""""50_products""""></div>"
    html html "</div>"
    html html "<div class=""""controls_container background"""">"
    html html "<span id=""""50_selected"""" style=""""font-size:20px;"""">KR</span>"
    html html "<a class=""""sale_button arrow expandProducts"""">"
    html html "<span>"
    html html "<div class=""""products"""">"
    html html "<span onClick=""""changeProduct(this,'KR');updateProduct(this)"""">KR</span>"
    html html "<span onClick=""""changeProduct(this,'LR');updateProduct(this)"""">LR</span>"
    html html "</div>"
    html html "</span>"
    html html "</a>"
    html html "<hr />"
    html html "<span class=""""sale_button plus"""" id=""""50_plus"""" onClick=""""incDecSale(this,'increase');updateProduct(this)""""></span>"
    html html "<input type=""""text"""" id=""""50_qty"""" readonly value=""""0""""/>"
    html html "<span class=""""sale_button minus"""" id=""""50_minus""""onClick=""""incDecSale(this,'decrease');updateProduct(this)""""></span>"
    html html "<hr />"
    html html "<input type=""""text"""" id=""""50_total"""" readonly value=""""£0""""/>"
    html html "</div>"
    html html "</form>"
    html html "</div>" 

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Of course it works the same in ASP.

    ASP invented the method; PHP copied it. Way back in 1997 or so.

    Code:
    <%
    For n = 50 To 57
    %>
    <div class="container"> 
        <form id="<%=n%>"> 
            <div class="image_container background"> 
                 ...
                <div class="selected_product" id="<%=n%>_products"></div> 
            </div> 
            <div class="controls_container background"> 
                <span id="<%=n%>_selected" style="font-size:20px;">KR</span> 
                <a class="sale_button arrow expandProducts"> 
                <span> 
                ... omitted ...
                <input type="text" id="<%=n%>_qty" readonly value="0"/> 
                <span class="sale_button minus" id="<%=n%>_minus"onClick="incDecSale(this,'decrease');updateProduct(this)"></span> 
                <hr /> 
                <input type="text" id="<%=n%>_total" readonly value="£0"/> 
            </div> 
        </form> 
    </div>
    <%
    Next
    %>
    
    But, by the by, ID's that consist of only digits are illegal (though accepted by all browsers at the current time).

    So I would use
    Code:
        <form id="form<%=n%>">
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    I got confused I though that in PHP I would do something like this:

    PHP Code:
    <?php
    $i 
    0;

    while (
    $i 5) {
    echo 
    ?>

    html...

    ...

    <?php
    }
    ?>
    So got it working now thanks. Also, why can't I thank your post?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Nope, your PHP was wrong.

    PHP would be essentially the same
    Code:
    <?php
    for ( $n = 50; $n <= 57; ++$n )
    {
    ?>
    <div class="container"> 
        <form id="<?=n?>"> 
        ...
    </div>
    <?php
    }
    ?>
    If you don't have short tags enabled in PHP, you'd have to do
    Code:
        <form id="<?php echo n; ?>">
    Which is pretty much equivalent to ASP's
    Code:
        <form id="<% response.write n %>">
    But thankfully, unlike PHP, ASP *always* enables short tags, so you CAN do just <%=n%>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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