I'm using MySQL to construct a texting system. Everything works superbly to date but I have to have the ability to do a particular factor.

Within the tables I've the column 'sender_id'.

I take this 'sender_id' and run it via a function which in turn retrieves the customers avatar and results the hyperlink within the came back JSON response.

I want this link... However I should also have the ability to retrieve the 'sender_id' itself like a number to ensure that I'm able to test against it in jquery.

What exactly I ultimately what's for that originaly 'sender_id' to become copied and set right into a type of virtual column 'before' it's been processed by my 'get avatar' function.

The code I'm using to output the JSON following the queries etc. is the following:-

/*
     * Output
     */
    $output = array(
        "sEcho" => intval($_GET['sEcho']),
        "iTotalRecords" => $iTotal,
        "iTotalDisplayRecords" => $iFilteredTotal,
        "aaData" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
        $row = array();
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( $aColumns[$i] == "version" )
            {
                /* Special output formatting for 'version' column */
                $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
            }
            if ( $aColumns[$i] == "sender_id" )
            {
                /* Special output to render Avatar by user id */
                $row[] = commentplayer_get_user_avatar($aRow[ $aColumns[$i] ]);

            }
            else if ( $aColumns[$i] == "message" )
            {
                /* General output */
                $row[] = strip_slashes($aRow[ $aColumns[$i] ]);
            }

            else if ( $aColumns[$i] != ' ' )
            {
                /* General output */
                $row[] = $aRow[ $aColumns[$i] ];
            }
        }
        $output['aaData'][] = $row;
    }

    echo json_encode( $output );
?>

$aColumns may be the variety of posts that are defined earlier, clearly 'sender_id' is just one of these. As you can tell I've include a conditional statement to ensure that the sender_id is retruned being an avatar link as opposed to the actual sender_id. To sumarise I simply need to have the ability to pull the particular sender_id out aswell because the avatar, ideally right into a separate column.

Any ideas?

You can include a line towards the code handling the column sender_id:

        if ( $aColumns[$i] == "sender_id" )
        {
            /* Output user id */
            $row[] = $aRow[ $aColumns[$i]] );
            /* Special output to render Avatar by user id */
            $row[] = commentplayer_get_user_avatar($aRow[ $aColumns[$i] ]);

        }

This can place the consumer id before the avatar URL in every came back JSON row-array.

Actually, it might be better to eliminate the for-loop within the posts, and merely fill $row using the products you'll need, listed in proper names rather than with respect to the order. This causes it to be simpler to determine what's really appended to $output. It will imply that when interpretation the JSON around the client, you'll have to treat the row being an object instead of an assortment.

    $row = array(
        "version"   => ($aRow["version"] == "0") ? '-' : $aRow["version"],
        "sender_id" => $aRow["sender_id"],
        "avatar"    => commentplayer_get_user_avatar($aRow["sender_id"]),
        "message"   => strip_slashes($aRow["message"]),
        // other items here
    );