scvinodkumar Posted September 28, 2009 Share Posted September 28, 2009 Hi i have a table contains information for different categories, category_id information 1 test1,test1.1,test1.2 2 test2,test2.1,test2.2 3 test3,test3.1,test3.2 .... Now, i want to display this like this, 1 2 3 test1 test2 test3 test1.1 test2.1 test3.1 test1.2 test2.2 test3.2 ... .. . . . so the first row contains category name and from second rows it contains information. How to bring this format in php? Link to comment https://forums.phpfreaks.com/topic/175781-table-format/ Share on other sites More sharing options...
jjacquay712 Posted September 28, 2009 Share Posted September 28, 2009 Hope this helps: <table> <?php $query = mysql_query("SELECT * FROM table;"); $number_of_results = mysql_num_rows($query); echo "<tr>"; for ( $n = 1; $n <= $number_of_results; $n++ ) { // Loop through the number of results and make a table row with the index echo "<td>" . $n . "</td>"; } echo "</tr>"; echo "<tr>"; while ( $result = mysql_fetch_array($query) ) { echo "<td>" . $result['information'] . "</td>"; // Loop through the database results and put it into a table row } echo "</tr>"; ?> </table> Link to comment https://forums.phpfreaks.com/topic/175781-table-format/#findComment-926390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.