jorge.chavez Posted April 8, 2007 Share Posted April 8, 2007 Hi, I am learning php, I have this code for a multiplication table and is not displaying anything, please let me know what is wrong <html> <head> <title>multiplication table</title> </head> <body> <?php print"<table border="1">\n"; for ($y=1;$y<=12;$y++) { print"<tr>\n"; for( $x=1; $x<=12; $x++) { print"\t<td>"; print ($x*$y); print "</td>\n"; } print "</tr>\n"; } print "</table>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted April 8, 2007 Share Posted April 8, 2007 Change line 7 to: print"<table border=\"1\">\n"; Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 um, use echo instead of print, and you dont need brackets around the multiplication....... how does that work??? Quote Link to comment Share on other sites More sharing options...
jorge.chavez Posted April 8, 2007 Author Share Posted April 8, 2007 thanks tippy, that did it in line 7, now, could you explain to me why this backslash?, sorry, Im just learning php Quote Link to comment Share on other sites More sharing options...
jorge.chavez Posted April 8, 2007 Author Share Posted April 8, 2007 what is the difference between echo and print? and why I should use print instead of echo? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 backslash escapes that character, like for example if you have ' string's' its an apostrophe, but you coud go 'string\'s or "string's" its the same thing but for longer strings and that, the backslash should be used youll also see it in \n, newline \t ( tab i think) its al over the place glad its working Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 from memory, print is more for formatting, echo is simply displaying data and stuff Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted April 8, 2007 Share Posted April 8, 2007 print"<table border=\"1\">\n"; Without the \ in front of the ", php thinks you are ending the print ". When php sees the \", it says to itself, "oh, I'm supposed to print that". Quote Link to comment Share on other sites More sharing options...
jorge.chavez Posted April 8, 2007 Author Share Posted April 8, 2007 great!! thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.