Jump to content

[SOLVED] dynimic row height


assgar

Recommended Posts

Hi

 

I am having a problem with the height of my dynamically create rows.

The data is retrived properly form the database, the issue is displaying the rows.

 

 

When there are alot of results to dusplay the rows are displayed correctly.

If there are a few rows the hight can be 3 times the height as when there alot of rows.

 

 

Note: Below is a simplified version of the code.

 

<?php	
     $query = "SELECT  event_id, event_date, event_time
	       FROM cal_appointment
	       WHERE status = 'A'
	       ORDER BY event_date, event_time";


     $result = mysqli_query($mysqli, $query) or die('Error, query failed');

   /************************ this section displays the events*************************/


   echo "<table width=\"100%\"  border=\"0\">";
    echo"<tr align=\"center\" bgcolor=\"#FFFFFF\">";
     echo" <td width=\"100%\" >
     <div id=\"Layer2\" style=\"position:absolute; width:100%; height:100px; z-index:2; left: 8px; top: 310px;\">
     <div id=\"scroll-box2\" style=\"overflow: auto; float: left; width: 100%; height: 240px;  margin: 5px; \">\n";

      //table begins
      echo "<table width=\"98%\" height=\"310\" left =\"4\" border=\"0\" font face =\"arial\">\n";

      $result = mysqli_query($mysqli,$query) or die('Error, query failed');
      $num_rows = mysqli_num_rows($result);
      for($i=0; $i < $num_rows; $i++)
{

    $row = mysqli_fetch_array($result);

  	    list($event_id, $event_date, $event_time) = $row;


    /**convert 24hr time to 12 hr**/
    list($hour, $min, $sec) = split(":",$event_time);

     if($hour > 12)
       {
	       	 $time_hour = $hour - 12;
       }
       else
	   {
		$time_hour = $hour;
	   }
     
     //format time of day
      if($hour < 12)
          {
	     $tod = "AM";
	  }
	  else
	      {
		  $tod = "PM";
	      }

   	     $time = "$hour:$min $tod";

     echo "<tr>";
	     echo"<td width=\"18%\" height=\"15\" align=\"center\">$time</td>
	  <td width=\"12%\"  height=\"15\">$event_date</td>\n";
             echo "</tr>";
      
      }//end for

     echo "</table>";
     echo "</td>";
     echo "</tr>";
     echo "</div>";
     echo "</div>";
     echo "</table>";

}

?>

Link to comment
Share on other sites

Perhaps remove the height from the table on this line:

echo "<table width=\"98%\" height=\"310\" left =\"4\" border=\"0\" font face =\"arial\">\n";

That way your rows wont expand to fill in the gaps if the height of the table doesn't exceed 310pixels.

Link to comment
Share on other sites

Hi Assgar,

 

This is just a quick suggestion... I reckon your problem is being created by the absolute positioning of the first div. Is there a way to do the following as they will all help:

 

  • Style your code using CSS, rather than using the HTML tags. for example:

echo '
<table style="width:99%; padding:0px;">
<tr>
<td style="width:5%; font-weight:900; background:#EBEBEB; padding:2px; text-align:left;">No.</td>
<td style="width:40%; font-weight:900; background:#EBEBEB; padding:2px; text-align:left;">Title</td>
<td style="width:20%; font-weight:900; background:#EBEBEB; padding:2px; text-align:left;">Date</td>
<td style="width:10%; font-weight:900; background:#EBEBEB; padding:2px; text-align:center;">Status</td>
<td style="width:25%; font-weight:900; background:#EBEBEB; padding:2px; text-align:center;">Action</td>
</tr>
</table>';

  • Possibly remove the absolute positioning?
  • Can you restrict the page to either tables or divs? It will make it easier to handle either way.

 

If there are any other containers on the page or declarations in a seperate CSS file, they could be responsible for the problem, such as body {height:100%}

 

I realise you may have thought of all this, but maybe give it a try to save yourself some time in troubleshooting  :)

 

Regards,

Iceman

Link to comment
Share on other sites

Hi

 

Thanks for the responses.

 

The problem is solved.

 

I removed the explicitly set the table height.

This prevents the rows from filling

the available height.

 

Although problem solved I will also try the css to explore the benifits.

 

<?php
echo "<table width=\"100%\"  border=\"0\">";
    echo"<tr align=\"center\" bgcolor=\"#FFFFFF\">";
     echo" <td width=\"100%\" >
     <div id=\"Layer2\" style=\"position:absolute; width:100%; height:100px; z-index:2; left: 8px; top: 310px;\">
     <div id=\"scroll-box2\" style=\"overflow: auto; float: left; width: 100%; height: 240px;  margin: 5px; \">\n";

      //table begins
      echo "<table width=\"98%\" height=\"\" left =\"4\" border=\"0\" font face =\"arial\">\n";

?>

Link to comment
Share on other sites

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.