Set column value to a link - PHP example code

Set column value to a link - PHP example code

sstryckersstrycker Posts: 6Questions: 0Answers: 0
edited May 2012 in General
Hello!

I've been working with your Datatables for a few days now and I have to say kudos! It's truly a fantastic piece of code :)

I've been trying to sort out a problem, I know enough PHP and javascript to be dangerous but maybe I don't know enough yet to make this work.

I'm using the example PHP code for server side data and I need one of the column's values to be a link to an edit form. I've been trying to get this functionality to work using this:

[code]
"fnInitComplete": function ( oSettings ) {
$(oTable.fnGetNodes()).click( function () {
var iPos = oTable.fnGetPosition( this );
var aData = oSettings.aoData[ iPos ]._aData;
location.href=('edit-projects.php?projectID='+aData[0]);
} );
}
[/code]

But I would actually rather just have one of the values come back from the server as a link instead!

I know it would probably have to be done somewhere near this codeblock:

[code]
while ( $aRow = mysql_fetch_array( $rResult ) )

{
$row = array();


for ( $i=0 ; $i
[/code]

Again, I'm not a PHP expert by any means, but I've played around with something like:

[code]
$aRow[5] = '

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    edited May 2012
    Something like this should do it:

    [code]
    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();

    for ( $i=0 ; $i
    [/code]

    Allan
  • sstryckersstrycker Posts: 6Questions: 0Answers: 0
    Allan, your a god of the code ;-)

    worked great!

    Just had to add the value to the link:

    [code]
    $row[] = '' . $aRow[$aColumns[$i]] . '';
    [/code]
This discussion has been closed.