0

I am using phpMyDataGrid , and I cannot make the dropdown list menu in a column.

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

This line doesn't work:

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

I get the following error:

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

line from 1077 to 1085 are following

                        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;  

And the FormatColumn() function is like this:

# 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;
            }
        }

Anybody can help? Thanks in advance

4
  • What does it mean "doesn't work"? Any error or something? Commented Mar 1, 2014 at 20:49
  • Yes it is error: Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/stem/phpmydatagrid.class.php on line 1079 Commented Mar 1, 2014 at 21:05
  • I'm assuming that line you provided is line 1079? Commented Mar 1, 2014 at 21:07
  • No Adi, I just update the question, and providing the error codes Commented Mar 1, 2014 at 21:14

1 Answer 1

1

On phpmydatagrid, when using a query as data input mask, the statement shall follow the pattern bellow:

SELECT key, value FROM table

Besides that, the parameter shall have the "select:" prefix. As an example, your statement should read:

$objGrid->FormatColumn("Personnel", "Personnel", 100, 100, 0, "100", "center","select:SELECT idPersonnel, name FROM Personnel");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.