Jump to content


Show Column names of dropdown box

  • Please log in to reply
No replies to this topic

#1 cyprus

  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 22 September 2006 - 11:11 PM

This may be a tall order, but I am trying to display column names above a dropdown list. I have code that puts data in a list in columns that are correctly spaced apart. I know that the column appears in the variable $cname, 5 lines down from the code below. My problem is $cname values appear multiple times where its echoed as its within code running for every row. Can someone offer suggestion as to how I can get a variable/array containing 1 set of column names that can be displayed either above the list or as a first row within the list. Thanks 

// get data lengths
      foreach ($data_rows as $k=>$row)
      foreach($row as $cname=>$val) {
      echo $cname;           
      $val = trim($val);

switch ($cname) {
        case 'UnitPrice':      $val = '£' . number_format($val,2); break;
        case 'Qty':    $val = number_format($val, 0) . ' off'; break;
        case 'RunningTotal':      $val = '£' . number_format($val,2); break;
        case 'Orderdate':  $val = date("j-M-Y", strtotime($val)); break;
        $data_rows[$k][$cname] = $val;
        $maxlen[$cname] = max($maxlen[$cname], strlen($val));

        $contents = "<select style=\"font-family:monospace;\" name=\"selectbox\" multiple size=\"$numrows\">\r\n";

        foreach ($data_rows as $row) {
        $id = $row['id'];
        unset ($row['id']);
        $contents .= "<option value='$id'>";
        $line = '';
        foreach($row as $cname=>$val) {
        $line .= str_pad($val, $maxlen[$cname]+2, chr(160));    //pad with non breaking spaces
        $contents .= $line;
        $contents .= "</option>\r\n";
        $contents .= "</select>";
        echo "<div>$contents</div>";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users