Jump to content

Recommended Posts

ok I need help with this one :o

 

Anyway, I want to have all the tables that my loop produces be the same height - so I thought adding padding to the bottom would be the easiest way. The problem is that I populate these tables base on a db field and I dont let the table have more than 15 check boxes

 

Here is my code for populating the tables:

<?php
			$max_per_col = 15;
			$current_type = "";
			$feature_num = 0;

			echo '<table border="1" cellspacing="0" cellpadding="0" align="left" style="padding-bottom:1em;"><tr>';

while ($row = mysql_fetch_assoc($rsAllFeatures)) {

  //If new type show new type header
  if ($current_type != $row['Type']) {

    //If not first type close previous type
    if ($current_type != "") {
      echo "</table><table border='1' cellspacing='0' cellpadding='0' align='left' style='padding-bottom:2em'>\n";
  $feature_num = 0;
    }

    $current_type = $row['Type'];
    echo "\n\t<tr><td class='sb' width='125' >$current_type:</td></tr>\n";

  }  
echo "<tr><td style=\"font-size:9px\" width='125' ><input onClick=\"changeColor(this.id, '#009900');\" type=\"checkbox\" name=\"FeatureId[]\" id=\"FeatureId$row[FeatureId]\" value=\"$row[FeatureId]\"";
					foreach($ItemsFeatures as $FeatureId){
						if($FeatureId==$row['FeatureId'])
							echo "checked";
					}
				echo ">";
echo "<label id=\"LabelFeatureId".$row['FeatureId']."\" for=\"FeatureId".$row['FeatureId']."\">".$row['Name']."</label></td></tr>\n";
  //echo $row['Name'] . "<br>\n";
  $feature_num++;

  //If the 15th item close td and start new one
  if ($feature_num >= $max_per_col) {
    echo "</table><table border='1' cellspacing='0' cellpadding='0' align='left' style='padding-bottom:2em'>\n";//"</td><td>\n";
    $feature_num = 0;
  }

}

echo "</td></tr></table>\n";?>

 

Any Ideas how to determine the extra padding needed at the end of each table?

 

possibly a count of some sort??

 

Link to comment
https://forums.phpfreaks.com/topic/67919-equal-padding-on-repeating-tables/
Share on other sites

yes, except I start a new table if the "type" is different.

 

I have a $feature_num but all my declarations are for starting the new table or tr - so if I say:

    if ($current_type != "") {
      $pad = 15 - $feature_num;
		echo "</table><table border='1' cellspacing='0' cellpadding='0' align='left' style='padding-bottom:".$pad."em'>\n";
  $feature_num = 0;
    }

 

I get the padding that should apply to the previous table not the current one.

 

Will I have to restructure my loops?

I think the best way to do it is to increment a counter ever time a row (<tr>) is printed in the current table. When you go to a new table, use that counter to print extra rows if it stops before that number. You can set a static height for all the rows or just put a   in the empty rows. If you don't want to add extra rows, I would still use the counter, but you would have to figure out a relation between padding and the number of rows in the previous table.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.