Jump to content

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


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;

  }

 

 

 

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.