naykidd Posted July 7, 2009 Share Posted July 7, 2009 So if i have an array that varies in how many sets of results there are, how would i go about putting it into a table of multiple rows, with column headings? Below is in my current code, and this just gives the results in a list , trying to put it into table of 4 columns, with as many rows of data as required, depending on the size of the array: <?php else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['Column1']}<br />{$row['Column2']}<br />{$row['Column3']}<br />{$row['Column4']}<br />{$row['Column5']}<br /><br />"; $i++; } } function removeEmpty($var) { return (!empty($var)); } ?> Tried to keep it short and to the point, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/165034-array-into-a-table/ Share on other sites More sharing options...
ignace Posted July 7, 2009 Share Posted July 7, 2009 <table> <tr> <th>Column Heading 1</th> <th>Column Heading 2</th> <th>Column Heading 3</th> <th>Column Heading 4</th> </tr> <?php if (mysql_num_rows($searchResult)) { while ($row = mysql_fetch_assoc($searchResult)) { print '<tr>'; print "\t<td>" . $row['column1'] . '</td>'; print "\t<td>" . $row['column2'] . '</td>'; print "\t<td>" . $row['column3'] . '</td>'; print "\t<td>" . $row['column4'] . '</td>'; print '</tr>'; } } else { print '<tr><td colspan="4">Search returned no results</td></tr>'; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/165034-array-into-a-table/#findComment-870353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.