Forum Moderators: coopster

Message Too Old, No Replies

Problems w/ using an include inside a table

Problems with using an include inside a table

         

megajam02

4:16 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



This is driving me nuts.

I have a form for my customers to register for events that my company is sponsoring. Inside the form is a table with various text fields, etc for my customers to fill in.

Some of our events are free, some are not. I built a separate page with the payment fields on it, and had hoped to include it on the registration form when the url passed a parameter of "?charge=yes". I had inserted an if statement in a cell in the table to call the include file.

The if statement works. When my urls is used like above, the include file shows, but it actually shows up on top of my other form, making the page largely unreadable.

Any idea what I'm doing wrong?

Thanks,
Chris

jatar_k

4:19 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld megajam02,

sounds more like an html problem. I would start by picking through the source of the page when the payments are included and see if you might have mismatched your table tags.

megajam02

4:38 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



Thanks jatar_k,
I'm pretty new to web design, so I'm not quite sure what you mean by having tags mismatched. Can you point me to a link or something with information on this?

Thanks for your help. Having people willing to share their knowledge has been a big help to me.

Chris

jatar_k

5:09 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, most html tags must be matched with an opening tag and a closing tag. When constructing tables it is very important to make sure that rows and cells are not only properly opened and closed but that we don't put the wrong number of cells in any particular row. That would cause the table to, literally, explode and throw content all over the page.

Let's try an example using a simplified index page with a basic table in it.

index.php

<html> 
<head><title></title></head>
<body>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td>This is</td>
<td>a 2 column table</td>
</tr>
<?php include "extrarows.html";?>
<tr>
<td>This row comes after</td>
<td>our included code</td>
</tr>
</table>
</body>
</html>

Now, the key is when including html code is to remember that the include happens inline. When the page is created it is parsed top to bottom. When the line with the include is hit, apache goes and grabs the code from that file and puts it into the page exactly where the include is placed.

That means that our included file will only have partial html in it. It will not be a full page on its own. Therefore no html, head, title or body tags as they have already occurred before our file was included. We must be careful to ensure that the resulting html that is sent to the browser is complete and properly constructed.

Let's look at what be in our 'extrarows.html' file. Let's say we want to include an extra row of data

extrarows.html

<!-- start included data --> 
<tr>
<td>this is our extra</td>
<td>row of data</td>
</tr>
<!-- end included data -->

We have to make sure that we have our row tags (tr) and the proper number of cells (td) or we will break the table.

If we were to look at the source of the index.php page through the browser we would see something like this

<html> 
<head><title></title></head>
<body>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td>This is</td>
<td>a 2 column table</td>
</tr>
<!-- start included data -->
<tr>
<td>this is our extra</td>
<td>row of data</td>
</tr>
<!-- end included data -->
<tr>
<td>This row comes after</td>
<td>our included code</td>
</tr>
</table>
</body>
</html>

Our inlcuded file has been inserted into the code where the include statement was located. That is why it is so important to make sure the html is correct. If we had more cells in our included row than the others, or if we didn't include the opening and closing tr tags, the resulting table wouldn't be properly constructed and we would blow it up.

does that help a bit?

megajam02

5:39 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



That helps VERY much.

I really appreciate you taking the time to help me. I think you nailed my problem, because my table definitely blew up on me. Now I just have to go back and figure out where I went wrong..

Thanks again.