Bogey Posted August 14, 2012 Share Posted August 14, 2012 (edited) Hi all, Is something like this possible? $a=1;while (blablabla)){<DIV id='idname_<?php echo $a;?>'></DIV>$a++;} This is what I want, but cant get it done :S Edited August 14, 2012 by Bogey Link to comment Share on other sites More sharing options...
justsomeguy Posted August 14, 2012 Share Posted August 14, 2012 All PHP code needs to be inside PHP tags. HTML markup that you want to output can either go in an echo or print statement, or outside PHP tags. Link to comment Share on other sites More sharing options...
Bogey Posted August 14, 2012 Author Share Posted August 14, 2012 Yes, that is what I am doing in the first post though? php echo is between <?php AND ?> I want my div id's made when page loads (number of divs are different on different times, so I don't know how many divs will apear)In each div is a button which can be clicked,but after click, that certain div needs to reload Hope I make myself clear a bit Link to comment Share on other sites More sharing options...
Bogey Posted August 14, 2012 Author Share Posted August 14, 2012 (edited) or do I need to echo that part inside the php, something like this: <?php$a=1;while (blabla){echo "<DIV id='item_" , $a . "'>";echo "</DIV>";}$a++; Edited August 14, 2012 by Bogey Link to comment Share on other sites More sharing options...
justsomeguy Posted August 14, 2012 Share Posted August 14, 2012 The problem is that the HTML markup is inside the PHP code. You have a while loop that you just put some HTML inside. PHP doesn't know what to do with HTML markup. That's one way to do it above. Link to comment Share on other sites More sharing options...
Bogey Posted August 14, 2012 Author Share Posted August 14, 2012 Yes that did it.... got it working! thnx thnx thnx Link to comment Share on other sites More sharing options...
Bogey Posted August 14, 2012 Author Share Posted August 14, 2012 I though PHP was a little more advanced Is the way I solved it a good/neat way, or is it bad? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 14, 2012 Share Posted August 14, 2012 I though PHP was a little more advancedThe "<" character is a less-than operator in PHP, it's not going to auto-detect HTML markup embedded in PHP code and assume you want to output that. It's up to you to tell it what to output. You can also do this: $a=1;while (blablabla)){?><DIV id='idname_<?php echo $a;?>'></DIV><?php$a++;} Link to comment Share on other sites More sharing options...
Bogey Posted August 14, 2012 Author Share Posted August 14, 2012 Your last post was I thought how I had it.... and did not work... Now I see I missed some <?php and ?>, maybe that was the issue.... I go look at that one next time.... now I need to sleep, eyes falling down and a busy day at work tomorrow hahaha thnx again anyway... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now