xionhack Posted November 22, 2009 Share Posted November 22, 2009 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? Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/ Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2009 Share Posted November 22, 2009 do you have any code ? which we can see so that we can have a better understanding of what your trying to do Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963121 Share on other sites More sharing options...
xionhack Posted November 22, 2009 Author Share Posted November 22, 2009 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; Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963155 Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2009 Share Posted November 22, 2009 would it not be better to do it is mysql SELECT COUNT(*) as song_count, name FROM playlist group by name Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963161 Share on other sites More sharing options...
xionhack Posted November 22, 2009 Author Share Posted November 22, 2009 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. Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963166 Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2009 Share Posted November 22, 2009 I still am not able to grasp what you mean by divide by two columns please elaborate on that. Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963169 Share on other sites More sharing options...
xionhack Posted November 22, 2009 Author Share Posted November 22, 2009 Never mind about the two columns, that I'll do with div. But I want to divide them in two tables. Half in one table, and half in the other Link to comment https://forums.phpfreaks.com/topic/182485-make-two-columns-of-almost-equal-size-with-the-data-from-tbl/#findComment-963397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.