Jump to content

help witht this table-column counter please? whey doesnt it break rows properly?


mac007

Recommended Posts

Hello, all:

 

have this tiny bit of code, and for the life of me, cant get the table-rows to break in the right place; it does it fine for very first row, but then it doesnt end rows accordingly for rest of records...  where should I be putting the tags??  appreciate help...

 

<CODE>

<?php

$columns = 0;

$columnsCounter = 2;

echo "<table border='1'>

<tr>";

while ($row = mysql_fetch_array($products))

{

echo "<td>" . $row['title']. "<br>";

 

echo " </td>";

$columns++;

if ($columns == $columnsCounter) { echo "</tr><tr>";  }

$columns == 0;

}

 

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

 

 

 

?>

</CODE>

at first glance you have a brace too many

   echo " </td>";
   $columns++;
   if ($columns == $columnsCounter) { echo "</tr><tr>";  }
   $columns == 0;
   }

should be

   echo " </td>";
   $columns++;
   if ($columns == $columnsCounter) { echo "</tr><tr>";  
   $columns == 0;
   }

ok, try

$columns = 0;
$columnsCounter = 2;
echo "<table border='1'>
<tr>";
while ($row = mysql_fetch_array($products)) {
   echo "<td>" . $row['title']. "<br> </td>";
   $columns++;
   if ($columns == $columnsCounter) { 
       echo "</tr><tr>";  
       $columns == 0;
   }
}
   echo "</tr></table>";

Thanks Harris...

 

hmm... no, didnt work, did same thing... it breaks first row at right place, but not rows after.. see image attached of how it's showing... where the "white mug" should be in new third row... but isnt! 

thanks for your help...

 

[attachment deleted by admin]

Well, found the error... I guess after you stare at code so long, one pretty much loses all real consciousness...

This section should have just one = (not ==)!!!  coudl kill mysself!!

 

if ($columns == $columnsCounter) {

      echo "</tr><tr>"; 

      $columns = 0;

  }

 

 

 

Archived

This topic is now archived and is closed to further replies.

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