Jump to content

[SOLVED] Imbedding php in html


ahvceo

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/158557-solved-imbedding-php-in-html/
Share on other sites

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

 

<!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>

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.