Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have a table components with n number of columns , but i need to display the columns in order or position passed as a parameters.

for example if i have 2 columns(Id,name) i need to pass a parameter 2 for id id to display it after the name so the result is (name,id)

anyone can help me please??!
Posted

1 solution

I assume you're putting the parameters into a server-side generated <table> element.

As you read each row of data from your query return, map it to an array element directly:
For example, if your have row element A, B, and C, and you wish to output them in the order B, C, A, then do the following:

if your sort order is in the array $order = (2,3,1);
PHP
$row = Get_The_Row_From_SQL_Return();

for($j=0; $j   $td[$order[$j]] = $row[j];

Now, use then array $td to create your table row:
PHP
 $rowText = '<table><tbody><tr>';

 foreach($td as $t)
   $rowText .= "<td>$t</td>";
 $rowText .= '';

</tr></tbody></table>


You have now generated a table with data element position remapped.

 
Share this answer
 
v2
Comments
MithalTirani 10-Jul-14 5:20am    
Sorry i'm using jasper table components to create a report

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900