Jump to content


This topic is now archived and is closed to further replies.


Show Column names of dropdown box

Recommended Posts

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>";

Share this post

Link to post
Share on other sites


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.