ahvceo Posted May 18, 2009 Share Posted May 18, 2009 Hi All, I got this off of the web because it looked like an interesting thing to try. If it works I would be able to fill a table from a database, which is something I would like to play with. Here's the code... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Make Table</title> </head> <body> <table> <tr> <?php for($l = 1; $l <=7; $l++): ?> <td align="center"> <?php if($l >= 5;) {echo "yes";} else {echo "no";} ?> </td> <?php endfor; ?> </tr> </table> </body> </html> It is supposed to create a table with 7 columns in 1 row with "no" in the first 5 columns and "yes" in the last 2. Of course the code doesn't work although it looks to me as if it should. Can anyone shed some light on why it doesn't work? And yet again the "echo" statement gives me nothing. Does the "echo" statement ever do anything? Thanks ahvceo Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/ Share on other sites More sharing options...
Daniel0 Posted May 18, 2009 Share Posted May 18, 2009 if($l >= 5;) should be if($l >= 5) It'll give you 4*no and 3*yes though. If you want 5 and 2 then you can change it to if($l > 5) Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/#findComment-836254 Share on other sites More sharing options...
ahvceo Posted May 18, 2009 Author Share Posted May 18, 2009 Hi Dannie10 Thanks for the quick reply. I tried your changes and I get the following output when I run it. 5) {echo "yes";} else {echo "no";} ?> Here's my code copied from the source... <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Make Table</title> </head> <body> <table> <tr> <?php for($l = 1; $l <=7; $l++): ?> <td align="center"> <?php if($l > 5) {echo "yes";} else {echo "no";} ?> </td> <?php endfor; ?> </tr> </table> </body> </html> Any suggestions? I would really like to be able to embed php to make tables. You could have a bunch of images in a database and display them in a nice grid. Thanks ahvceo Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/#findComment-836280 Share on other sites More sharing options...
Daniel0 Posted May 18, 2009 Share Posted May 18, 2009 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Make Table</title> </head> <body> <table> <tr> <?php for($l = 1; $l <=7; $l++): ?> <td align="center"> <?php if($l > 5) {echo "yes";} else {echo "no";} ?> </td> <?php endfor; ?> </tr> </table> </body> </html> Will output: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Make Table</title> </head> <body> <table> <tr> <td align="center"> no </td> <td align="center"> no </td> <td align="center"> no </td> <td align="center"> no </td> <td align="center"> no </td> <td align="center"> yes </td> <td align="center"> yes </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/#findComment-836285 Share on other sites More sharing options...
wildteen88 Posted May 18, 2009 Share Posted May 18, 2009 @ahvceo Make sure you're placing your code within .php files, as by default PHP is only parsed within these files. You should also make sure your host allows you to use PHP Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/#findComment-836540 Share on other sites More sharing options...
ahvceo Posted May 19, 2009 Author Share Posted May 19, 2009 Thank You Dannie10. My problem was that I wasn't saving it as php. It now works fine and I can now try some interesting things ahvceo Quote Link to comment https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/#findComment-836877 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.