Home Forums Tech Database PHP: how to get field length from MySQL

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #4173
    VGlushkin
    Participant

    You defined a PHP associative array like this:

    $fLen = array (
    “ID” => $statement->getColumnMeta ( 0 ) [‘len’]/3,
    “LastName” => $statement->getColumnMeta ( 1 ) [‘len’]/3,
    “FirstName” => $statement->getColumnMeta ( 2 ) [‘len’]/3,
    “Company” => $statement->getColumnMeta ( 3 ) [‘len’]/3,
    “SearchType” => $statement->getColumnMeta ( 4 ) [‘len’]/3,
    “ActivityCode” => $statement->getColumnMeta ( 5 ) [‘len’]/3,
    “Status” => $statement->getColumnMeta ( 6 ) [‘len’]/3,
    “AccountNum” => $statement->getColumnMeta ( 7 ) [‘len’]/3,
    “DateEntered” => $statement->getColumnMeta ( 8 ) [‘len’]/3,
    “DateModified” => $statement->getColumnMeta ( 9 ) [‘len’]/3,
    “KeyWords” => $statement->getColumnMeta ( 10 ) [‘len’]/3,
    “Remark” => $statement->getColumnMeta ( 11 ) [‘len’]/3,
    “PrintForAlex” => $statement->getColumnMeta ( 12 ) [‘len’]/3,
    “PrintForLira” => $statement->getColumnMeta ( 13 ) [‘len’]/3,
    “ModifiedBy” => $statement->getColumnMeta ( 14 ) [‘len’]/3
    );

    But now you really would like to access your arra by an int indes instead of the name. Here is how you can do this”
    $fLenKeys = array_keys($fLen);
    for( $i = 0; $i <= 14; $i++ )
    echo (‘ $fLen[$fLenKeys[‘ . $i . ‘]] => ‘ . $fLen[$fLenKeys[$i]] . ‘<br>’);

    You can see in the output something like this:

    $fLen[$fLenKeys[0]] => 3.3333333333333
    $fLen[$fLenKeys[1]] => 32
    $fLen[$fLenKeys[2]] => 32
    $fLen[$fLenKeys[3]] => 64
    $fLen[$fLenKeys[4]] => 16
    $fLen[$fLenKeys[5]] => 16
    $fLen[$fLenKeys[6]] => 16
    $fLen[$fLenKeys[7]] => 32
    $fLen[$fLenKeys[8]] => 6.3333333333333
    $fLen[$fLenKeys[9]] => 6.3333333333333
    $fLen[$fLenKeys[10]] => 64
    $fLen[$fLenKeys[11]] => 128
    $fLen[$fLenKeys[12]] => 1.3333333333333
    $fLen[$fLenKeys[13]] => 1.3333333333333
    $fLen[$fLenKeys[14]] => 64

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.