gobbles Posted April 17, 2007 Share Posted April 17, 2007 Hey All, I have a database with a list of careers. I want to pull the careers from the database and display them in a table, only problem is that i need them to be displayed in 2 columns, in other words, if i have "Chef" and "Bricky" instead of easily pulling them and listing them, i want them to be side by side, 50 / 50 in 2 columns of a table. Can anybody help me out? Cheers Link to comment https://forums.phpfreaks.com/topic/47328-quick-table-question/ Share on other sites More sharing options...
rcorlew Posted April 17, 2007 Share Posted April 17, 2007 This might help you get a good start: <?php // Connect to MySQL database $con = mysql_connect($HOST, $USER, $PASS); if (!$con) { // Since the entire script depends on connection, die if connection fails die("Error connecting to MySQL database!"); } mysql_select_db($NAME, $con); function getCareers($careers) { $days = array(); $sql = mysql_query("SELECT * COUNT(career_id) FROM career_table"); if (mysql_num_rows($sql) > 0) { while ($row = mysql_fetch_array($sql)) $careers[] = $row['careers']; } return $careers; } function drawCareerTable($careers) { // Start drawing calendar $out = "<table id=\"myCareer\">\n"; $out .= "<tr><th colspan=\"2\">Careers</th></tr>\n"; $out .= "<tr>\n"; foreach ($careers as $c) $out .= "<td class=\"isCareer\">$c</td>\n"; $i = 0; for ($e = (1 - $offset); $e <= $careers; $e++) { if ($i % 2 == 0) $out .= "<tr>\n"; // Start new row if ($e < 1) $out .= "<td class=\"nonCareer\"> </td>\n"; else { if (in_array($c, $careeres)) { $out .= "<td class=\"isCareer\">\n"; $out .= "$c\n"; $out .= "</td>\n"; } else $out .= "<td class=\"isCareer\">$c</td>\n"; } ++$i; // Increment position counter if ($i % 2 == 0) $out .= "</tr>\n"; // } // Round out last row if we don't have any more careers if ($i % 2 != 0) { for ($j = 0; $j < (2 - ($i % 7)); $j++) { $out .= "<td class=\"nonCareer\"> </td>\n"; } $out .= "</tr>\n"; } $out .= "</table>\n"; return $out; } echo drawCareerTable($careers); ?> It should work just adjust the tablename and stuff to suit your needs Link to comment https://forums.phpfreaks.com/topic/47328-quick-table-question/#findComment-230915 Share on other sites More sharing options...
gobbles Posted April 17, 2007 Author Share Posted April 17, 2007 Dang .. Thanks heaps for that Link to comment https://forums.phpfreaks.com/topic/47328-quick-table-question/#findComment-230920 Share on other sites More sharing options...
rcorlew Posted April 17, 2007 Share Posted April 17, 2007 Your welcome and good luck on your project. Link to comment https://forums.phpfreaks.com/topic/47328-quick-table-question/#findComment-230930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.