Page 1 of 1

looped table within table

Posted: Tue Jul 02, 2002 12:47 am
by mrpaulfrank
ill try to explain as i go along:

Code: Select all

<table width="100%" border="0" cellspacing="0" cellpadding="0"> // begin master table
  <tr> // begin master table's only row
    while ()
		&#123; // begin while loop 	
		<td>  // begin master table column to be repeated by loop
			<table width="25%" border="0" cellspacing="0" cellpadding="0">  // begin sub-table in master table column
  			<tr>  // sub-table row 1
    			<td><div align="center">$image</div></td>
  			</tr>  //end sub-table row 1
  			<tr>  // sub-table row 2
   	 			<td><div align="center">$title</div></td>
  			</tr>  // end sub-table row 2
  			<tr>  // sub-table row 3
    			<td><div align="center">$make</div></td>
  			</tr>  // end sub-table row 3
  			<tr>  // sub-table row 4
    			<td><div align="center">$var</div></td>
			</tr>  // end sub-table row 4
			</table>  //end sub-table
		</td>  //end master table column
		&#125;  //end loop
  </tr> //end master table row
</table> //end master table

hopefully this is self-explanatory or i drew it out well enough for everyone to see. im pretty sure my html is correct here, but my problem is all the php syntax within the loop. can someone help me out here by giving all the correct,error-free syntax. no matter how hard i try i can never get the errors worked out. i thought a 'clean' version would be easier to work with if someone feels like tackling it. thanks.

Posted: Tue Jul 02, 2002 12:58 am
by protokol
The first thing you need to remember is that when you are embedding PHP code in an HTML page, you need to explicitly use the PHP tags: <?php ?>

Example:

Code: Select all

<html>
<body>

<table border="0">
<tr>
<?php
   $x = 0; // set initial counter value
   while ($x < 5) &#123; // loop goes through 4 iterations
?>
<td>
   <table border="1">
   <tr>
      <td>Inner table #<?php echo $x; ?></td>
   </tr>
   </table>
</td>
<?php
      $x++; // increment the count
   &#125;
?>
</tr>
</table>

</body>
</html>
The above code would be saved as a .php file. It basically goes through a loop 4 times, each time printing the <table> code. As you can see, each time a PHP statement is used, it is described by using <?php ?> tags. This is necessary in order to let the parser know that it's encountering PHP code which needs to be processed.

Hope this helps

Posted: Tue Jul 02, 2002 1:24 am
by mrpaulfrank
my problem lies in the parse errors im receiving within the loop...not how many times its run (im controlling the record navigation already). maybe playing with the code ive already posted for the tables...inserting where i should start <?php and end it ?> etc. also inserting proper punctuation where i need it would help. thanks

Posted: Tue Jul 02, 2002 1:26 am
by protokol
Well if you look at the way you set up your loop, there is no <?php ?> tag and also, it doesn't have an 'echo' or 'print' statement telling it to print the table.

This is why you get parse errors

Posted: Tue Jul 02, 2002 1:33 am
by mrpaulfrank
i just didnt put the echo or php tags in this post. of course theyre in my script. how should i treat all that table info that i posted first if im trying to echo it (thats what i was originaly asking...echo the entire loop). should i be using ".;" and where?

Posted: Tue Jul 02, 2002 1:42 am
by kaizix

Code: Select all

while () 
      &#123; // begin while loop     
      echo "<td>\n";  // begin master table column to be repeated by loop 
         echo "<table width="25%" border="0" cellspacing="0">\n";
and so on and so forth. just make sure to escape all the " other the ones for the echo statement. the \n is a carriage return which will put whatever is in the the next statement on a new line.

Posted: Tue Jul 02, 2002 1:56 am
by mrpaulfrank
thanks a million. damn those "...i forgot you need to escape them. man i was going crazy for a while there! haha