Pergunta

I am using the example for server side datatables plugin http://datatables.net/examples/data_sources/server_side.html

It works fine, but now I'm trying to change the code for my table, because the example is not exactly how I want my table to look like.

There is one problem :

{
    $row = array();
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( $aColumns[$i] == "setid" )
        {
            $row[] = ($aRow[ $aColumns[$i] ]) ? '<a href=\'http://osu.ppy.sh/d/$aRow[ $aColumns[$i]]\'>test</a>'  : $aRow[ $aColumns[$i] ];
        }
        else if ( $aColumns[$i] != ' ' )
        {
            /* General output */
            $row[] = $aRow[ $aColumns[$i] ];
        }
    }
    $output['aaData'][] = $row;
}

The problem is right here :

$row[] = ($aRow[ $aColumns[$i] ]) ? '<a href=\'http://osu.ppy.sh/d/$aRow[ $aColumns[$i]]\'>test</a>'  : $aRow[ $aColumns[$i] ];

When I click "test" in my table it goes to http://osu.py.sh/d/$aRow[$aColumns[$i] ]] instead of the ID.

As far as I know the ID I need is in $aRow[ $aColumns[$i]]; How can I solve this problem?

Foi útil?

Solução

You need double quotes for variable names to be be expanded inside a string.

However, as you are using 3 variables, I would concatenate the string instead to avoid confusion:

$row[] = $aRow[ $aColumns[$i] ]
           ? ('<a href=\'http://osu.ppy.sh/d/' . $aRow[$aColumns[$i]] . '\'>test</a>')
           : $aRow[ $aColumns[$i] ];

Outras dicas

Try changing this line

$row[] = ($aRow[ $aColumns[$i] ]) ? '<a href=\'http://osu.ppy.sh/d/$aRow[ $aColumns[$i]]\'>test</a>'  : $aRow[ $aColumns[$i] ];

to

$row[] = ($aRow[ $aColumns[$i] ]) ? '<a href=\'http://osu.ppy.sh/d/'.$aRow[ $aColumns[$i]].'\'>test</a>'  : $aRow[ $aColumns[$i] ];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top