Jump to content

Make two columns of almost equal size with the data from tbl


xionhack

Recommended Posts

Hello. I have a table that has a list of songs. I want with that data to make 2 columns to list them in a website. I tried this:

 

Counted the rows

Divided the rows by 2

Took the floor of that for the first column

Then substracted that floor by the amount counted for the second column

 

But I havent been able to display them in the html. Can somebody help me?

I know this code is totally wrong in the loop part! but this is all i have!

 

global $connection;

$count = "SELECT COUNT(name)
     FROM playlist";
$count = mysql_query($count, $connection);
confirm_query($count);
$count = mysql_fetch_array($count);

$songs = "SELECT name
              FROM playlist";
$songs = mysql_query($songs, $connection);
confirm_query($songs);

$column1 = floor($count['COUNT(name)'] / 2);

$column2 = $count['COUNT(name)'] - $column1;

$output .= "<table>";


while($song_list = mysql_fetch_array($songs))
{
         for($i = 1; $i <= $column1; $i++){
	$output .= 
		"<tr>
		   <td>" .
			$i . " " . $song_list['name'] .
		   "<td>
		 <tr>";
			          }				
}

$output .="</table>";
return $output;

I dont know if that will do what im trying to do. Let me give an example. If in the table I have 5 colors (blue, red, green, black, white), I want it to display like this:

 

 

<table>
    <tr>
      <td>Black</td>
    </tr>
<tr>
      <td>Blue</td>
    </tr>
</table>

<table>
    <tr>
      <td>Green</td>
    </tr>
<tr>
      <td>Red</td>
    </tr>
<tr>
      <td>White</td>
    </tr>
</table>

 

I want all the colors divided in 2 columns.

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.