Jump to content

[SOLVED] How to Handle Query With Unknown Number of Results in 2 Columns?


limitphp

Recommended Posts

If I have a query that could return 0 or multiple results and I want to display them in a table in two columns, how do I handle it if there are an odd number of results and the second column won't get written?

 

Ex)

<table>
<?php
//query
$count = 1
while ($row_artist = mysql_fetch_assoc($result_artist_search))
{
     if($count & 1) //odd
     {
     echo "<tr>
                 <td>
                    <?php echo $row_artist['name'] ?>
                 </td>";
      }
      else //even
      {
          echo "<td>
                    <?php echo $row_artist['name'] ?>
                 </td>
             </tr>";
      }

      $count++;              

}
?>
</table>

 

What would be the best practice to handle displaying these artists if there are an odd number of them and I want to display them in two columns?

 

Right now, it wouldn't close the row if there are an odd number of artists.

thanks

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.