2014-03-01 27 views
0

我正在使用phpMyDataGrid,我不能在列中的下拉列表菜单。phpMyDataGrid选择字段,dynamiclly从其他表中下拉列表菜单

$objGrid = new datagrid; 
$objGrid->closeTags(true); 
$objGrid->friendlyHTML(); 
$objGrid->methodForm("get"); 
$objGrid->conectadb("localhost", "root", "", "STEM_DB"); 
$objGrid->salt("Myc0defor5tr0ng3r-Pro3EctiOn"); 
$objGrid->language("en"); 
$objGrid->buttons(true,true,true,false); 
$objGrid->Form('grant', true); 
$objGrid->searchby("GrantName"); 
$objGrid->tabla ("GrantProgram"); 
$objGrid->keyfield("GrantID"); 
$objGrid->datarows(20); 
$objGrid->orderby("GrantName", "ASC"); 
$objGrid->FormatColumn("GrantID", "Grant ID", 5, 5, 0, "5", "center", "integer"); 
$objGrid->FormatColumn("GrantName", "Grant Name", 20, 20, 0, "100", "center", "text"); 
$objGrid->FormatColumn("Funder", "Funder", 20, 20, 0, "100", "center", "text"); 

此行不起作用:

$objGrid->FormatColumn("Personnel", "Personnel", 100, 100, 0, "100", "center","SELECT 
* FROM Personnel"); 

我得到以下错误:

Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/stem/phpmydatagrid.class.php on line 1079

行1077年至1085年跟随

     case 'select': 
          $strInput.= "<select id='$fldname' class='dgSelectpage' >$br"; 
          foreach ($selData as $key=>$value){ 
           $selected=($value==$default)?"selected='selected'":""; 
           $strInput.= "<option value='$key' $selected. >$value</option>$br"; 
          } 
          $strInput.= "</select>";  
          $campos[] = $fldname; 
         break; 

而FormatColumn()函数是这样的:

# FormatColumn: Define fields to show and their settings 
function FormatColumn($strfieldName, $strHeader, $fieldWidth=0, $maxlength=0, $inputtype=0, $columnwidth=0, $align= 'center', $Mask='text', $default='', $cutChar=0){ 
    if ($strfieldName=="" or !$this->validField($strfieldName)){ 
     $mask = strtolower($Mask); 
     $this->fieldsArray["$strfieldName"]["strfieldName"] = $strfieldName;   # Field Name 
     $this->fieldsArray["$strfieldName"]["strHeader"] = $strHeader;    # Title to show in top of grid 
     $this->fieldsArray["$strfieldName"]["fieldWidth"] = $fieldWidth;   # Input size 
     $this->fieldsArray["$strfieldName"]["maxlength"] = $maxlength;    # Input maxlength 
     $this->fieldsArray["$strfieldName"]["columnwidth"] = intval($columnwidth)."px"; # Column width 
     $this->fieldsArray["$strfieldName"]["align"]  = $align;     # Left, center, right, justify 
     $this->fieldsArray["$strfieldName"]["mask"]   = $Mask;     # Mask for data output 
     $this->fieldsArray["$strfieldName"]["default"]  = $default;    # Default value for new records 
     $this->fieldsArray["$strfieldName"]["select"]  = '';      # Auxiliar field for data in masks (check, select) 

     $this->fieldsArray["$strfieldName"]["cutChar"]  = $cutChar;    # Amount of chars to show. 

     $datatype='text'; 
     if ($mask=='textarea') $datatype='textarea'; 
     if (substr($mask,0,5)=='image') $datatype='image'; 
     if (substr($mask,0,9)=='imagelink'){ $datatype='imagelink'; } 
     $pmask = !(strpos($this->numerics,trim($mask)) === false); 
     if (substr($mask,0,5)=='money' or $pmask)$datatype='number'; 
     if (substr($mask,0,4)=='date') $datatype='date'; 
     if (substr($mask,0,4)=='link') $datatype='link'; 
     if (substr($mask,0,4)=='calc') {$datatype='calc'; $this->hasCalcs = "true"; echo "<script type='text/javascript'> var thereisCalc = true;</script>"; $inputtype=3; } 
     if (substr($mask,0,5)=='chart'){$datatype='chart'; $this->hasChart = true; $inputtype=5; 
      if (strpos($mask,':') > 0) { 
       $arrMask=explode(':',$Mask); $arrMask=array_slice($arrMask,1); 
      }else{ 
       $arrMask=array("none:sum"); 
      } 
      $this->fieldsArray["$strfieldName"]["select"] = $arrMask; 
     }  
     if (substr($mask,0,4)=='bool' or substr($mask,0,5)=='check'){ $datatype='check'; 
      if (strpos($mask,':') > 0) { 
       $arrMask=explode(':',$Mask); $arrMask=array_slice($arrMask,1); 
      }else{ 
       $arrMask=array($this->message['false'],$this->message['true']); 
      } 
      $this->fieldsArray["$strfieldName"]["select"] = $arrMask; 
     }  
     if (substr($mask,0,6)=='select'){ $datatype='select'; 
      $maskData = array(); 
      if (strpos($mask,':') >0){ 
       $mask=explode(':',$Mask); 
       if (strtoupper(substr($mask[1],0,7)) == 'SELECT ') {     #Select data from Table. Format [SELECT key, value FROM table] 
        if ($this->isADO){ 
         if (($objResult = $this->connectionHandler->Execute($mask[1])) === false) 
           $this->SQLerror($mask[1],$this->connectionHandler->ErrorMsg()); 
         while (!$objResult->EOF){ 
          $arrResult = $objResult->fields; 
          $maskData[$arrResult[0]]=$arrResult[1]; 
          $objResult->MoveNext(); 
         } 
        }else{ 
         $objResult = mysql_query($mask[1]) or $this->SQLerror($mask[1], mysql_error()); 
         while ($arrResult = mysql_fetch_array($objResult)) 
          $maskData[$arrResult[0]]=$arrResult[1]; 
        } 
       }else{                 #literal select: keyfield must be of the same datatype as the list 
        $arrMask=array_slice($mask,1); 
        foreach ($arrMask as $ArrData) { 
         $arrOptions = explode('_', $ArrData); 
         $rowID = $arrOptions[0]; 
         if (isset($arrOptions[1])) $rowName = $arrOptions[1]; else $rowName = $rowID; 
         $maskData[$rowID]=$rowName; 
        } 
       } 
       $this->fieldsArray["$strfieldName"]["select"] = $maskData; 
      } 
     } 

任何人都可以提供帮助吗?在此先感谢

+0

这是什么意思“不起作用”?任何错误或什么? –

+0

是的,它是错误的:警告:无效的参数提供了foreach()在/Applications/XAMPP/xamppfiles/htdocs/stem/phpmydatagrid.class.php在线1079 – user3369279

+0

我假设你提供的行是行1079? –

回答

1

phpmydatagrid,使用查询作为数据输入掩码时,该声明应遵循波纹管模式:

SELECT key, value FROM table 

除此之外,参数应具有“选择:”前缀。 作为一个例子,您的陈述应为:

$objGrid->FormatColumn("Personnel", "Personnel", 100, 100, 0, "100", "center","select:SELECT idPersonnel, name FROM Personnel"); 
相关问题