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> Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/ 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"; Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224265 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??? Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224266 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 Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224269 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? Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224273 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 Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224274 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 Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224275 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". Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224276 Share on other sites More sharing options...
jorge.chavez Posted April 8, 2007 Author Share Posted April 8, 2007 great!! thanks guys Link to comment https://forums.phpfreaks.com/topic/46142-solved-help-with-multiplication-code/#findComment-224298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.