MasterACE14 Posted May 21, 2009 Share Posted May 21, 2009 With this example script on tizag.com I can display the array with 1 record per line. But how can I make it display in 2 columns? <?php echo "<table>"; $employeeAges["Lisa"] = "28"; $employeeAges["Jack"] = "16"; $employeeAges["Ryan"] = "35"; $employeeAges["Rachel"] = "46"; $employeeAges["Grace"] = "34"; $employeeAges["Robert"] = "32"; foreach( $employeeAges as $key => $value){ echo "<tr>"; echo "<td style=\"border: 1px solid black;\">"; echo "Name: $key, Age: $value <br />"; echo "</td>"; echo "</tr>"; } echo "</table>"; ?> it comes up like... Name: Lisa, Age: 28 Name: Jack, Age: 16 Name: Ryan, Age: 35 Name: Rachel, Age: 46 Name: Grace, Age: 34 Name: Robert, Age: 32 but I want to make it come up like... Name: Lisa, Age: 28 Name: Jack, Age: 16 Name: Ryan, Age: 35 Name: Rachel, Age: 46 Name: Grace, Age: 34 Name: Robert, Age: 32 Regards, ACE Quote Link to comment https://forums.phpfreaks.com/topic/159076-solved-2-columns-when-displaying-array/ Share on other sites More sharing options...
Jibberish Posted May 21, 2009 Share Posted May 21, 2009 did this quickly but it should work. <?php echo "<table>"; $employeeAges["Lisa"] = "28"; $employeeAges["Jack"] = "16"; $employeeAges["Ryan"] = "35"; $employeeAges["Rachel"] = "46"; $employeeAges["Grace"] = "34"; $employeeAges["Robert"] = "32"; $count = 0; foreach( $employeeAges as $key => $value){ if($count%2 == 0) echo "<tr>"; echo "<td style=\"border: 1px solid black;\">"; echo "Name: $key, Age: $value "; echo "</td>"; if($count%2 == 1) echo "</tr>"; $count++; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159076-solved-2-columns-when-displaying-array/#findComment-838923 Share on other sites More sharing options...
MasterACE14 Posted May 21, 2009 Author Share Posted May 21, 2009 yep it did! thankyou heaps! Quote Link to comment https://forums.phpfreaks.com/topic/159076-solved-2-columns-when-displaying-array/#findComment-838925 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.