Jump to content

Problem with html table


Bravat

Recommended Posts

First the code:

<?php $columns = 4;
$num_results = mysql_num_rows($result);
$col_rows = intval($num_results / $columns);
$count = 1; ?> 
      <table cellspacing="2" class="tabela">
    
                 <tr> <td>
                	   <?php 
   while ($row = mysql_fetch_array($result))  {
   $count = $count++;
  $title = $row["Rim"];  
  $model = $row["model"];
  $dimenzija = $row["Dimenzija"];
  $ime = $row['name']; 
  echo "$model<br>$dimenzija<br>$ime" ;
  
  if ($count == $col_rows) {
echo "</td>\n";
echo "<td>\n";
$count = 1;
}} ?>    </td>
          </tr>   
                             
    </table>

 

(table is 100% width and td is 25%)

Problem with this is that td will go in linear like structure. I want it after 4 td's to go into new row (something like <br> tag). How to do this? Also when their is one result, td is 100% width (it stretch across hole screen). How to define it to be 25% at all time?

 

 

Link to comment
Share on other sites

  <?php $columns = 4;
$num_results = mysql_num_rows($result);
$col_rows = intval($num_results / $columns);
$count = 1; ?> 
      <table cellspacing="2" class="tabela">
    
                 <tr> <td>
                	   <?php 
   while ($row = mysql_fetch_array($result))  {
   $count = $count++;
  $title = $row["Rim"];  
  $model = $row["model"];
  $dimenzija = $row["Dimenzija"];
  $ime = $row['name']; 
  echo "$model<br>$dimenzija<br>$ime" ;
  
  if ($count == $col_rows) {
echo "<br>$count</td></tr><tr>";
echo "<td>";
$count = 1;
} }?>    </td>
          </tr>   
                             
    </table>

 

It seems that counter does not work. The echo result of $count is 1.

Link to comment
Share on other sites

I managed to make it work. Here is the code

$go = TRUE;
?>

<table cellspacing="2" class="tabela">
	<?php while ($go) { ?>
		<tr>
            <?php for ($i = 0; $i < 4; $i ++) {                 	
                     if (!($row = mysql_fetch_array($result))) { 
                        $go = FALSE; 
                        CONTINUE; 
        				} 
                    $title = $row["Rim"];  
                    $model = $row["model"];
                    $dimenzija = $row["Dimenzija"];
                    $ime = $row['name']; 
  
        echo "<td>$model<br>$dimenzija<br>$ime</td>";
                    }
                ?>
        
        </tr> 
        <?php } ?>
</table>
<?php unset ($row); 
unset ($Go);  ?>

 

But the problem with row width is still there. If there is only 1 result it will be 100% wide, 2 results 25% wide and so on. Any idea how to stop this?

Link to comment
Share on other sites

I looked around the web and there is one way to make it work. It is needed to add rows to fill the gap, but at the moment i don't know how to do this. I tried this code but it does not work.

$go = TRUE;
?>

<table cellspacing="2" class="tabela">
	<?php while ($go) { ?>
		<tr>
            <?php for ($i = 0; $i < 4; $i ++) {                 	
                     if (!($row = mysql_fetch_array($result))) { 
                        $go = FALSE; 
                        CONTINUE; }
        			$title = $row["Rim"];  
                    $model = $row["model"];
                    $dimenzija = $row["Dimenzija"];
                    $ime = $row['name']; 
  
        echo "<td>$model<br>$dimenzija<br>$ime</td>";
        }  if ($i < 4){
        echo "<td></td>";
        }
        			 ?>
        </tr> 
        <?php } ?>
</table>
<?php unset ($row); 
unset ($Go);  ?>

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.