Jump to content

Quick Table Question


gobbles

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.