Jump to content

doing a tutorial... but \n isnt working!


BigCanadian

Recommended Posts

This is the code Im testing


<?php
for ($i = 1; $i < 3; $i = $i + 1) {
  for ($j = 1; $j < 4; $j = $j + 1) {
      for ($k = 1; $k < 3; $k = $k + 1) {
        print "I: $i, J: $j, K: $k\n";
      }
  }
}
?>




and it says it will output this

I: 1, J: 1, K: 1
I: 1, J: 1, K: 2
I: 1, J: 2, K: 1
I: 1, J: 2, K: 2
I: 2, J: 1, K: 1
I: 2, J: 1, K: 2
I: 2, J: 2, K: 1
I: 2, J: 2, K: 2



but instead it gives me this



I: 1, J: 1, K: 1 I: 1, J: 1, K: 2 I: 1, J: 2, K: 1 I: 1, J: 2, K: 2 I: 1, J: 3, K: 1 I: 1, J: 3, K: 2 I: 2, J: 1, K: 1 I: 2, J: 1, K: 2 I: 2, J: 2, K: 1 I: 2, J: 2, K: 2 I: 2, J: 3, K: 1 I: 2, J: 3, K: 2


help please as to why the \n is not working
Link to comment
https://forums.phpfreaks.com/topic/28054-doing-a-tutorial-but-n-isnt-working/
Share on other sites

I just had a similar problem. If you view the source code it will display what its supposed to, but it doesn't. The browser reads \n as whitespace. You have to use <br> instead.

[code]<?php
for ($i = 1; $i < 3; $i = $i + 1) {
  for ($j = 1; $j < 4; $j = $j + 1) {
      for ($k = 1; $k < 3; $k = $k + 1) {
        print "I: $i, J: $j, K: $k<br>";
      }
  }
}
?>[/code]
wow this language is vast eh... oh well... I really hope if I dedicate my time to it Ill understand it haha... I think my main problem will be understanding how MySql databases work.. ohhh well I spose Ill just keep reading these tutorial you showed me thorpe.

I gotta say they are much clearer than the other ones on php.net... but that example (the one I posted above) with all those nested things really confused me

In my mind it keeps computing like it should count each variable up to the designated amount... for example 3 for $i and 4 for $j... etc will this come easier to me later or am I doomed to not see this connection... I mean if you were to nest a whole bunhc of tables and row frame and columns in front of me I could tell you in no time what it would look like... will php get this way for me? I know its kind of a rhetorical question... but any assurance (even if its false rhetorical assurance) is better than nothing hahah. thanks again for the help guys!

Biggie C

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.