Dec to HEX conversion

Dec to HEX conversion

WaynefWaynef Posts: 9Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
HI All

I am using a MySQLi data connection example ( http://datatables.net/development/server-side/php_mysqli ) to retrieve the required data, this is working great but the information in the Database is stored in a decimal format. I need to display this as a Hex value.

I there a method to do this? I have search and date's can be reformatted and numbers formatted to show thousands etc, but nothing for hex.

Any pointers would be appreciated.

Regards

Wayne

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    I usually favour letting the database do the work where possible.
    MySQL has a conv() function which converts numbers between different number bases, but I couldn't say whether MySQLi has it.
  • WaynefWaynef Posts: 9Questions: 0Answers: 0
    Thanks but I am not sure where how i change the php code to incorporate the conversion. I am new to web design and self taught so some assistance would be greatly appreciated.

    Cheers
  • allanallan Posts: 63,577Questions: 1Answers: 10,483 Site admin
    General SQL functions falls outside the scope of this forum to be honest. You'd probably be better off asking generic PHP or SQL questions somewhere like StackOverflow. Look up how to use the MySQL function `conv()` that tangerine mentioned for example.

    Allan
  • WaynefWaynef Posts: 9Questions: 0Answers: 0
    HI all

    I have now managed to modify the data in the JSON data when using a MYSQLI script.

    [code]
    while ( $aRow = $rResult->fetch_assoc() ) {
    $row = array();
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
    if ( $aColumns[$i] == 'version' ) {
    // Special output formatting for 'version' column
    $row[] = ($aRow[ $aColumns[$i] ]=='0') ? '-' : $aRow[ $aColumns[$i] ];
    } elseif ( $aColumns[$i] != ' ' ) {
    // General output
    $row[] = $aRow[ $aColumns[$i] ];
    }
    }
    $row[1] = sprintf("%X",($row[1]));
    $output['aaData'][] = $row;
    }

    echo json_encode( $output );
    [/code]

    I have been able to do this by adding this $row[1] = sprintf("%X",($row[1])); line, it basically modifies the data in the array for the second column in the table. In this case converting the Decimal value into a Hex value.

    Thanks for assistance

    Wayne
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Nice. It never occurred to me to use sprintf().
This discussion has been closed.