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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
gobbles Posted April 17, 2007 Author Share Posted April 17, 2007 Dang .. Thanks heaps for that Quote Link to comment 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. Quote Link to comment 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.